Zoj3556 How Many Sets I ------- reject

Source: Internet
Author: User

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 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.