YT03-遞推求解課堂題目-1005 Children’s Queue-(6.7日-煙臺大學ACM預備隊解題報告)
Children’s Queue
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 77 Accepted Submission(s) : 29
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
There are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other words, either no girl in the queue or more than one girl stands side by side.
The case n=4 (n is the number of children) is like
FFFF, FFFM, MFFF, FFMM, MFFM, MMFF, MMMM
Here F stands for a girl and M stands for a boy. The total number of queue satisfied the headmaster’s needs is 7. Can you make a program to find the total number of queue with n children?
FFFF, FFFM, MFFF, FFMM, MFFM, MMFF, MMMM
Here F stands for a girl and M stands for a boy. The total number of queue satisfied the headmaster’s needs is 7. Can you make a program to find the total number of queue with n children?
Input
There are multiple cases in this problem and ended by the EOF. In each case, there is only one integer n means the number of children (1<=n<=1000)
Output
For each test case, there is only one integer means the number of queue satisfied the headmaster’s needs.
Sample Input
1 2 3
Sample Output
1 2 4
Author
Source
杭電ACM集訓隊訓練賽(VIII)
#include<stdio.h>
int main()
{
int n;
int f[1001][101] = {0};
f[0][1] = 1;
f[1][1] = 1;
f[2][1] = 2;
f[3][1] = 4;
for(int i = 4; i < 1001; ++i)
{
for(int j = 1; j < 101; ++j)
{
f[i][j] += f[i - 1][j] + f[i - 2][j] + f[i - 4][j];
f[i][j + 1] += f[i][j] / 10000;
f[i][j] %= 10000;
}
}
while(scanf("%d", &n) != EOF)
{
int k = 100;
while(!f[n][k--]);
printf("%d", f[n][k + 1]);
for(; k > 0; --k)
{
printf("%04d", f[n][k]);
}
printf("\n");
}
return 0;
}
相關文章
- YT03-遞推求解課堂題目-1001 蟠桃記-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課堂題目-1002 折線分割平面-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課堂題目-1004 不容易系列之一-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課後題目-1001 母牛的故事-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課後題目-1002 超級樓梯-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課堂題目-1003 獻給杭電五十週年校慶的禮物-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課後題目-1006 不容易系列之(4)——考新郎-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課堂題目-1003—數塔-(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課後題目-1003 不容易系列之(3)—— LELE的RPG難題-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課堂題目-1004—最少攔截系統-(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課堂練習-1005—Wooden Sticks-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課後題目-1004—Max Sum -(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課後題目-1001—FatMouse's Speed-(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課後題目-1003—免費餡餅 -(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課後題目-1002—Super Jumping! Jumping! Jumping! -(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課堂練習-1004—Fire Net-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課堂練習-1001 今年暑假不AC-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課後練習-1004—迷瘴-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課後練習-1006—PAINTER(6.14日-煙臺大學ACM預備隊解題報告)AIACM
- YT06-揹包-1001—Bone Collector -(6.27日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課後練習-1002—Repair the Wall-(6.14日-煙臺大學ACM預備隊解題報告)AIACM
- YT06-揹包-1002—Piggy-Bank -(6.27日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課後練習-1003—悼念512汶川大地震遇難同胞——老人是真餓了-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT06-揹包-1003—悼念512汶川大地震遇難同胞——珍惜現在,感恩生活 -(6.27日-煙臺大學ACM預備隊解題報告)ACM
- 河南理工大學程式設計(ACM)大賽解題報告程式設計ACM
- 活動預告|網路安全攻與防專題課堂
- 杭電ACM hdu 2079 選課時間 解題報告(母函式)ACM函式
- ACM(遞迴遞推—A)ACM遞迴
- 大學畢業課題研究開題報告PPT分享-20套可下載
- NYNU ACM 藍橋杯選拔賽 解題報告ACM
- 山東省第四屆acm解題報告(部分)ACM
- ACM(遞迴遞推—I)ACM遞迴
- 樹遞迴問題的求解遞迴
- 杭電ACM hdu 2152 Fruit 解題報告(母函式)ACMUI函式
- c++求解獎券題目C++
- 測試面試題目求解答面試題
- 杭電ACM hdu 1398 Square Coins 解題報告(母函式)ACM函式
- 杭電ACM hdu 2110 Crisis of HDU 解題報告(母函式)ACM函式