鑰匙計數之一(遞推)hdu1438,鑰匙計數hdu1438

來源:互聯網
上載者:User

鑰匙計數之一(遞推)hdu1438,鑰匙計數hdu1438
鑰匙計數之一Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1471    Accepted Submission(s): 622


Problem Description一把鎖匙有N個槽,槽深為1,2,3,4。每鎖匙至少有3個不同的深度且至少有1對相連的槽其深度之差為3。求這樣的鎖匙的總數。 
Input本題無輸入 
Output對N>=2且N<=31,輸出滿足要求的鎖匙的總數。 
Sample Output

N=2: 0N=3: 8N=4: 64N=5: 360..............N=31: ...註:根據Pku Judge Online 1351 Number of Locks或 Xi'an 2002 改編,在那裡N<=16
 


轉載請註明出處:尋找&星空の孩子 

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1438

 

 

/*1:如果X是鑰匙, 則X1/2/3/4也是, 所以a[I]=a[I-1]*42: 如果X不是, X2/3是則X由1/4組成, 但要除去全1和全4, 所以a[I]+=(2^(I-1)-2)*2尾碼2或者3加上就成為鑰匙的話,必然是沒滿足需要3個不同深度槽這一項,故X必然由1/4組成3 如果X不是 X1/4是。則X=Y(1/4) M=X1/4=Y(4/1)(1/4)前I-2位可以是1234,但要除去全為1/4的情況 還有就是X是鑰匙且X是以1/4結尾的情況。我們用b[I]數組表示i位時以1/4結尾的的數量   temp=(4^(i-2)-2^(i-2))* 2 – b[i-1];則 b[i]=a[i-1]*2+temp;*/#include<stdio.h>#define LL long long#include<string.h>LL a[35],b[35];LL ppow(LL n,LL m){    LL c=1;    while(m)    {        if(m&1) c=c*n;        n=n*n;        m>>=1;    }    return c;}int main(){    a[0]=a[1]=a[2]=0;    b[0]=b[1]=b[2]=0;    LL temp=0;    printf("N=2: 0\n");    for(int i=3;i<=31;i++)    {        temp=(ppow(4,i-2)-ppow(2,i-2))*2-b[i-1]; //       printf("temp=%lld\t",temp);        b[i]=a[i-1]*2+temp;        a[i]=a[i-1]*4+(ppow(2,i-1)-2)*2+temp;        printf("N=%d: %lld\n",i,a[i]);    }    return 0;}


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.