The meaning of the topic is very clear, can not alone have a girl to stand together.
Suppose there are n individuals.
1. The last person is a boy, then there is f (N-1).
2. The last person is a girl, and the first N-1 is a girl, then there is f (N-1).
But another is that the first N-2 is a girl, (is the boy's words, included in F (N-1)), but the first N-3 is a boy, is not included in the above situation, but also in line with. That is, the last three girls, the fourth is the boy. There are also F (N-4) species.
So there is a recursive formula: F (N) = f (N-1) + f (N-2) + f (N-4).
The following is the code for the AC:
#include <iostream> #include <cstring>using namespace Std;char num[1001][300];void Add (int x, int y)// Large number add function {int Temp[300];int len1 = strlen (num[x]); int len2 = strlen (num[y]); int I, j, k = 0;for (i = len1-1, j = len2-1; I >= 0 && J >= 0; I--, j--) {temp[k++] = num[x][i]-' 0 ' + num[y][j]-' 0 ';} while (I >= 0) {temp[k++] = num[x][i--]-' 0 ';} while (J >= 0) {temp[k++] = num[y][j--]-' 0 ';} for (i = 0; i < k-1; i++) {if (Temp[i] >=) {temp[i + 1] + = Temp[i]/10;temp[i]%= 10;}} if (Temp[k-1] >=) {temp[k] = Temp[k-1]/10;temp[k-1]%= 10;k++;} i = K-1;j = 0;while (i >= 0) {num[x][j++] = temp[i--] + ' 0 ';} Num[x][k] = ' + ';} int main () {int i;num[0][0] = ' 1 '; num[0][1] = ' num[2][0 '; num[1][0] = ' 1 '; num[1][1] = ' + '; num[2][1] = ' 2 ';] = ' n '; num [3] [0] = ' 4 '; Num[3][1] = ' + '; num[4][0] = ' 7 '; Num[4][1] = ' + '; for (i = 5; I <=, i++) {strcpy (Num[i], num[i-1]), add (I, i-2); Add (i, i-4);} while (Cin >> i) {cout << num[i] << Endl;} return 0;}
Application of Acm1297--children ' s queue~~ large number addition in Hangzhou Electric Power Co.,