Give a set S, |S| = n, then how many ordered set group (S1, S2, ..., Sk) satisfies S1 ∩ S2 ∩ ... ∩ Sk = ∅. (Si is a subset of S, (1 <= i <= k))
Input
The input contains multiple cases, each case have 2 integers in one line represent n and k(1 <= k <= n <= 231-1), proceed to the end of the file.
Output
Output the total number mod 1000000007.
Sample Input
1 1 2 2
Sample Output
1 9
整套比赛最简单的一个。
可以直接写一个暴力程序,然后找规律。
规律很显然的~
我的代码:
#include<stdio.h>
#include<iostream>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll power(ll p,ll n,ll m)
{
ll sq=1;
while(n>0)
{
if(n%2==1)
sq=(sq%m)*(p%m)%m;
p=(p%m)*(p%m)%m;
n=n/2;
}
return sq%m;
}
int main()
{
ll n,k,ans;
while(cin>>n>>k)
{
ans=power(2,k,mod)-1;
ans=power(ans,n,mod);
cout<<ans<<endl;
}
return 0;
}
如何计算集合的组合数
本文介绍了如何通过编程计算集合中不相交子集的总数,并提供了代码实现。
1766

被折叠的 条评论
为什么被折叠?



