How Many Sets I

来源:互联网 发布:古筝曲谱制作软件 编辑:程序博客网 时间:2024/05/09 11:20
How Many Sets I

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 12 2

Sample Output

19
个数为n的集合的子集有2^n个,从中选出K个使得他们的交集为空的个数。
由于集合可以重复被选,所以总的数目是2^(kn)
然后选中的集合都包含x这个数的数目是c(n,1)*2^(n-1)k
选中的集合包含x1,x2的数目是c(n,2)*2^(n-2)k
……
所以满足的集合的个数res=2^kn-c(n,1)*2^(n-1)k+c(n,2)*2(n-2)k-……
推出的公式为(2^k-1)^n
[cpp] view plaincopy
  1. #include<iostream>  
  2. #include<cstdlib>  
  3. #include<stdio.h>  
  4. using namespace std;  
  5. #define mm 1000000007  
  6. typedef long long ll;  
  7. ll powermod(ll a,ll b)  
  8. {  
  9.     ll res=1;  
  10.     while(b)  
  11.     {  
  12.         if(b&1)res=(res*a)%mm;//不能写成res*=a%mm~~~~~~~~~  
  13.         a=a*a;  
  14.         a%=mm;  
  15.         b>>=1;  
  16.     }  
  17.     return res%mm;  
  18. }  
  19. int main()  
  20. {  
  21.     ll n,k;  
  22.     while(scanf("%lld%lld",&n,&k)!=EOF)  
  23.     {  
  24.         ll ans=powermod(2,k);  
  25.         ans--;  
  26.         ans=powermod(ans,n);  
  27.         printf("%lld\n",ans);  
  28.     }  
  29. }  
0 0
原创粉丝点击