Children’s Queue

xiaoxiao2021-02-28  109

Children’s Queue

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14919    Accepted Submission(s): 4956 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?   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  这题爆int了,表示对大数有点小阴影啊,多练习吧。加油 #include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <stack> #include <vector> #include <algorithm> #include <map> using namespace std; #define INF 0x3f3f3f3f #define CLR(a,b) memset(a,b,sizeof(a)) #define PI acos(-1.0) #define LL long long int a[1001][110] = {0}; void add(int n){ int k = 0, j; for(j = 1; j < 101; j++){ k += a[n-1][j] + a[n-2][j] + a[n-4][j]; a[n][j] = k000; k = k/10000; } /*while(k){ a[n][j++] = k % 10000; k = k/10000; }*/ } int main(void){ //freopen("题.txt", "r", stdin); a[1][1] = 1; a[2][1] = 2; a[3][1] = 4; a[4][1] = 7; int n, i; for(i = 5; i <= 1000; i++){ add(i); } while(scanf("%d", &n) != EOF){ for(i = 100; i > 0; i--){ if(a[n][i] != 0) break; } printf("%d", a[n][i]); for(i = i - 1; i > 0; i--){ printf("d", a[n][i]); } printf("\n"); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-32791.html

最新回复(0)