HDU 2065 红色病毒问题(生成函数)
生活随笔
收集整理的這篇文章主要介紹了
HDU 2065 红色病毒问题(生成函数)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Time Limit: 1000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8679????Accepted Submission(s): 3525
現(xiàn)在有一長度為N的字符串,滿足一下條件:
(1) 字符串僅由A,B,C,D四個(gè)字母組成;
(2) A出現(xiàn)偶數(shù)次(也可以不出現(xiàn));
(3) C出現(xiàn)偶數(shù)次(也可以不出現(xiàn));
計(jì)算滿足條件的字符串個(gè)數(shù).
當(dāng)N=2時(shí),所有滿足條件的字符串有如下6個(gè):BB,BD,DB,DD,AA,CC.
由于這個(gè)數(shù)據(jù)肯能非常龐大,你只要給出最后兩位數(shù)字即可.
?
Input 每組輸入的第一行是一個(gè)整數(shù)T,表示測試實(shí)例的個(gè)數(shù),下面是T行數(shù)據(jù),每行一個(gè)整數(shù)N(1<=N<2^64),當(dāng)T=0時(shí)結(jié)束.?
Output 對(duì)于每個(gè)測試實(shí)例,輸出字符串個(gè)數(shù)的最后兩位,每組輸出后跟一個(gè)空行.?
Sample Input 4 1 4 20 11 3 14 24 6 0?
Sample Output Case 1: 2 Case 2: 72 Case 3: 32 Case 4: 0 Case 1: 56 Case 2: 72 Case 3: 56?
Author Rabbit?
Source RPG專場練習(xí)賽?
Recommend lcy???|???We have carefully selected several similar problems for you:??2067?2064?2068?2063?2066? 生成函數(shù) 對(duì)于$A,C$和$B,D$分別構(gòu)造多項(xiàng)式 因?yàn)槭桥帕袉栴},所以用指數(shù)型生成函數(shù) 下圖為mjt大佬的課件,有一部分寫錯(cuò)了,大家自己代入推推就好 最后$x^n$的系數(shù)就是答案?
// luogu-judger-enable-o2 #include<cstdio> #include<cstring> #include<algorithm> #define int long long const int MAXN = (1 << 21) + 10, mod = 100; inline int read() { char c = getchar(); int x = 0, f = 1;while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f; } int fastpow(int a, int p) {int base = 1;while(p) {if(p & 1) base = (base * a) % mod;a = (a * a) % mod;p >>= 1;}return base % mod; } main() {#ifdef WIN32freopen("a.in","r",stdin);#endif int QwQ = 0;while(scanf("%d", &QwQ) && QwQ != 0) {int now = 0;for(int i = 1; i <= QwQ; i++) {int x = read();printf("Case %I64d: %I64d\n", ++now, (fastpow(4, x - 1) + fastpow(2, x - 1)) % mod);}puts("");} }?
?
總結(jié)
以上是生活随笔為你收集整理的HDU 2065 红色病毒问题(生成函数)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 新站上线后应该做哪些有利于seo的工作
- 下一篇: ignite自定义函数