Http://acm.hdu.edu.cn/showproblem.php?pid=5363Key Set
Time limit:2000/1000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 549 Accepted Submission (s): 338
Problem Descriptionsoda has a setSWithNIntegers< Span id= "mathjax-span-8" class= "Mrow" >{ 1, 2,... , n} . A set is called key set if the sum of integers in the set are an even number. He wants to know how many nonempty subsets Of s are key set.
Inputthere is multiple test cases. The first line of input contains an integerT(1≤T≤5) , indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤9) the number of integers in the set.
Outputfor each test case, output the number of key sets modulo 1000000007.
Sample Input41234
Sample Output0137
int Pow (int a, int b)
{
int ans = 1;
while (b)
{
if (b% 2 = = 1)
Ans *= A;
A *= A;
b/= 2;
}
return ans;
}//the power of fast number to the power of B
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespacestd;#defineN 500Long LongPow (Long LongALong LongBLong Longc) { Long LongAns =1; A%=C; while(b) {if(b%2==1) ans= (ans * a)%C; A= (A * a)%C; b/=2; } returnans;}//The power of the fast number, the B power of A, C is to take the remainder of CintMain () {intT; Long LongN, Num; scanf ("%d", &t); while(t--) {scanf ("%lld", &N); Num= Pow (2N1,1000000007); printf ("%lld\n", Num-1); } return 0;}
HDU 5363 Key Set