Test instructions: A set has element 1~n that satisfies the condition that all elements of a subset are of an even number, asking how many such subsets
Analysis:
A permutation combination problem. Elements and is even, then the odd number must be adjusted even numbers, even if it does not matter, so even there is 2^ (N/2) Seed selection method, and then multiplied by odd (C ((n+1)/2,0) +c ((n+1)/2,2) ... Seed selection method, minus one, remove the empty set, note that the above is used when the odd number (n+1)/2 (here is the division of the downward rounding), is a combination of n is even and N is an odd two cases.
Combination Number properties: C (n,1) +c (n,3) +....=c (n,2) +c (n,4) +....=1/2* (c (n,1) +c (n,2) + ... C (N.N)) =1/2* (2^n) =2^ (n-1) (n is an odd even number that satisfies this property)
Now Bashi the sub-merge (where the division is true division, so N is an odd time to be +1 or 1 to divide):
When 1.N is even, even there are 2^ (N/2), Odd 2^ (N/2)/2 kinds of extraction, integrated ans=2^ (n-1)-1
When 2.N is odd, even there are 2^ ((n-1)/2), Odd 2^ ((n+1)/2), Integrated ans=2^ (N-1) 1
The rest is the quick power to take the mold, this method is very basic to remember it.
Code:
#include <cstdio> #include <iostream> #define INF 1000000007using namespace Std;int t;long long N;long long ans ; Long long f (long long a,long long B,long long c) { long long t = 1; while (b) { if (b&1) t= (t*a)%inf; b>>=1; A= (a*a)%inf; } return t; }int Main () { scanf ("%d", &t); while (t--) { scanf ("%i64d", &n); Ans=f (2,n-1,inf); Ans-=1; printf ("%i64d\n", ans);} }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5363 elements for a set of 1~n how many subsets of elements and for even-thinking-(Fast power modulo)