莫的难题
题目大意
给你五个数,每个数字可以重复选,让你找出第C(n,m) % 1e9+7大的数。
题解
可以先写出C(n,m)的表,
于是题就变成了求由这些数组合成的第k大的数。
怎么求?
把k变成五进制~~(哇妙啊 太妙了)~
然后输出第几位就好了。
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <cstring>
#include <string>
#include <bitset>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
#define st first
#define sd second
#define mkp make_pair
#define pb push_back
void wenjian(){
freopen("concatenation.in","r",stdin);freopen("concatenation.out","w",stdout);}
void tempwj(){
freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){
return b == 0 ? a : gcd(b,a % b);}
ll qpow(ll a,ll b,ll mod){
a %= mod;ll ans = 1;while(b){
if(b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;}
struct cmp{
bool operator()(const pii & a, const pii & b){
return a.second > b.second;}};
int lb(int x){
return x & -x;}
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9+7;
const int maxn = 105;
ll c[maxn][maxn];
int a[6] = {
1,2,3,5,9};
std::vector<int> vv;
int main()
{
int T;
scanf("%d",&T);
c[0][0] = 1;
for (int i= 1; i <= 100; i ++ )
{
c[i][1] = i;
for (int j = 2; j <= i; j ++ )
{
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
// printf("%lld ",c[i][j]);
}
// for (int j = 1; j <= i; j ++ )
// printf("%lld ",c[i][j]);
// printf("\n");
}
while(T -- )
{
vv.clear();
int n,m;
scanf("%d%d",&n,&m);
ll k = c[n][m];
// ll k;
// scanf("%lld",&k);
// printf("%lld\n",k);
//把k转化成5进制
while(k)
{
vv.pb((k - 1) % 5);
k = (k - 1)/5;
}
for (int i = vv.size() - 1; i >= 0; i -- )
{
// printf("%d",vv[i]);
printf("%d",a[vv[i]]);
}
printf("\n");
}
}