首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

HDU 4349 Xiao Ming's Hope 结合数学

2012-09-13 
HDU4349Xiao Mings Hope组合数学来源:http://acm.hdu.edu.cn/showproblem.php?pid4349题意:求C(n,0),C(n,

HDU 4349 Xiao Ming's Hope 组合数学

来源:http://acm.hdu.edu.cn/showproblem.php?pid=4349

题意:求C(n,0),C(n,1),C(n,2)...C(n,n).当中有多少个奇数。

思路:表示比赛时是水过的,求出了前8个数,发现都是2的幂,然后就发现规律了。就是n转化为二进制后又多少个1,就是2的多少次方。解题报告说是Lucas定理,不知道Lucas定理是什么,也没看懂证明。。太弱了

代码:

#include <iostream>#include <cstdio>#include <string.h>using namespace std;int fun(int x){int s = 0;while(x){  int y = x % 2;  if(y)  s++;  x /= 2;}return s;}__int64 mi(int x){__int64 s = 1;for(int i = 1; i <= x; ++i)s *= 2;return s;}int main(){int n;while(scanf("%d",&n) != EOF){   int cnt = fun(n);   __int64 ans = mi(cnt);   printf("%d\n",ans);}return 0;}


热点排行