HDU 4349 Xiao Ming's Hope

來源:互聯網
上載者:User

標籤:數論   組合數學   

很無語的一個題。

反正我後來看題解完全不是一個道上的。

要用什麼組合數學的lucas定理。

表示自己就推了前面幾個數然後找找規律。

C(n, m) 就是 組合n取m;


(m!(n-m!)/n!)

如果n==11 ;

C(11,0);C(11,1);C(11,2);C(11,3);C(11,4);C(11,5);

分別為

(1/1); (1 / 11) ; (11*10 / 2*1)  ;   (11*10*9 / 3*2*1); (11*10*9*8 / 4*3*2*1) ;  (11*10*9*8*7 / 5*4*3*2*1);


C(11,11);C(11,10);C(11,9);C(11,8);C(11,7);C(11,6);

這兩個都是相等的。(參見排列組合)


若要 C(n,m)為奇數,必須  分子分母 約分後都是奇數。

發現如果純類比的肯定會逾時的。

當時發現 當n==2^?  都是可以被除掉的,就只有 C(n,0);和 C(n,n) 都是 1,奇數。

而 n==(2^?)-1 的時候結果就是 2^n 。

然後推了前面幾個數


1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16

2,2,4,2,4,4,8,2,4,4  ,8  ,4  ,8  ,8  ,16,2 


巨像 樹狀數組。。。想到樹狀數組是取& 。

然後我就 轉換 n 的二進位。發現有m個1 ,結果就是 2^m ;


於是終於AC。→ _ → 數學好伐。


#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<queue>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<cmath>#define INF 0x7fffffff#define eps 1e-6using namespace std;int shift(int n){    int cot=0;    while(n)    {        if(n%2==1)cot++;        n/=2;    }    return cot;}int main(){    int n,m;    while(scanf("%d",&n)!=EOF)    {        m=shift(n);        cout<<pow(2,m)<<endl;    }}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.