生活随笔
收集整理的這篇文章主要介紹了
hdu 4349——Xiao Ming's Hope
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給定n,讓求c(n,0),c(n,1)……c(n,n)中有多少奇數。
思路:本題為Lucas定理推導題,我們分析一下 C(n,m)%2,那么由lucas定理,我們可以寫
- 成二進制的形式觀察,比如 n=1001101,m是從000000到1001101的枚舉,我們知道在該定理中
- C(0,1)=0,因此如果n=1001101的0對應位置的m二進制位為1那么C(n,m) % 2==0,因此m對應n為0的
- 位置只能填0,而1的位置填0,填1都是1(C(1,0)=C(1,1)=1),不影響結果為奇數,并且保證不會
- 出n的范圍,因此所有的情況即是n中1位置對應m位置0,1的枚舉,那么結果很明顯就是:2^(n中1的個數)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int INF=
0x3fffffff;
const int inf=-INF;
const int N=
1e5+
5;
const int M=
2005;
const int mod=
1000000007;
const double pi=
acos(-
1.0);
#define cls(x,c) memset(x,c,sizeof(x))
#define cpy(x,a) memcpy(x,a,sizeof(a))
#define ft(i,s,n) for (int i=s;i<=n;i++)
#define frt(i,s,n) for (int i=s;i>=n;i--)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
#define middle int m=(r+l)>>1
#define lowbit(x) (x&-x)
#define pii pair<int,int>
#define mk make_pair
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)int read() {
char ch;
while (ch = getchar(), !
isdigit(ch));
int res = ch -
'0';
while (ch = getchar(),
isdigit(ch))res = res *
10 + ch -
'0';
return res;
}
ll powm(ll a,ll n,ll m){ll ans=
1;
while (n){
if (n&
1) ans=ans*a%m;a=a*a%m;n>>=
1;}
return ans%m;
}
int main()
{
int n;
while (~
scanf(
"%d",&n)){
int sum=
0;
while (n){sum+=n&
1;n>>=
1;}
printf(
"%d\n",(
1<<sum));}
}
總結
以上是生活随笔為你收集整理的hdu 4349——Xiao Ming's Hope的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。