题目链接:点击进入
题目
题意
n 个人, >= k 人就可以组成一个小组,问能组成多少个小组
思路
答案 = c ( n , k ) + … + c ( n , n )
= 2 ^ n - ( c ( n , 0 ) + … + c ( n , k - 1 ) )
c ( n , i ) = c ( n , i - 1 ) * ( n - i + 1 ) / i
i 的逆元: 1 / i = i ^ ( mod - 2 )
代码
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define INF 0x3f3f3f3f
#define pii pair<int, int>
//#define pdi pair<double,int>
//#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
const int maxn=1e6+10;
const int mod=1e9+7;
int t,n,m,k,tot;
ll qpow(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1) res=res*a%mod;
b=b>>1;
a=a*a%mod;
}
return res;
}
int main()
{
cin>>t;
while(t--)
{
cin>>n>>k;
ll ans=qpow(2,n)-1,res=1;
for(int i=1;i<=k-1;i++)
{
res=(res*(n-i+1))%mod*qpow(i,mod-2)%mod;
ans=(ans-res+mod)%mod;
}
printf("Case #%d: %lld\n",++tot,ans);
}
return 0;
}