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 then... sk = large. (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
There are 2 ^ n subsets of a set whose number is n, and K are selected from them to make their intersection null.
Because the set can be selected repeatedly, the total number is 2 ^ (kn)
Then the selected set contains the number of x, which is c (n, 1) * 2 ^ (n-1) k.
The selected set contains x1, and the number of x2 is c (n, 2) * 2 ^ (n-2) k
......
So the number of satisfied sets res = 2 ^ kn-c (n, 1) * 2 ^ (n-1) k + c (n, 2) * 2 (n-2) k -......
The formula is (2 ^ k-1) ^ n.
[Cpp]
# Include <iostream>
# Include <cstdlib>
# Include <stdio. h>
Using namespace std;
# Define mm 1000000007
Typedef long ll;
Ll powermod (ll a, ll B)
{
Ll res = 1;
While (B)
{
If (B & 1) res = (res * a) % mm; // res * = a % mm ~~~~~~~~~
A = a *;
A % = mm;
B> = 1;
}
Return res % mm;
}
Int main ()
{
Ll n, k;
While (scanf ("% lld", & n, & k )! = EOF)
{
Ll ans = powermod (2, k );
Ans --;
Ans = powermod (ans, n );
Printf ("% lld \ n", ans );
}
}