1011_Xiao_Ming's_Hope

题目:

hdu_4349_Xiao_Ming's_Hope

 

官方题解:

本题为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的个数)

 

个人理解:

正如题解所说,本题是Lucas定理的直接应用。当然也可以多写几个答案,看出答案与N的关系是2^(n中1的个数)。

   Lucas定理:      

For non-negative integers m and n and a prime p, the following congruence relation holds:



where



and



are the base p expansions of m and n respectively.


定理还不会证。

 

标程:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int lowbit(int x) {
    return x & (-x);
}

int get_result(int n) {
    int res = 0;
    while (n) {
        n -= lowbit(n);
        res++;
    }
    return res;
}

int main() {
 //   freopen("data.in", "r", stdin);
 //   freopen("data.out", "w", stdout);
    int n;
    while (scanf("%d", &n) != EOF) {
        printf("%d\n", 1 << get_result(n));
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值