problem DescriptionThe 1th line of the symbol triangle has n a symbol consisting of "+" and "-", each line is 1 less than the upstream, 2 are "+" under the same number, and 2 are "-" under the different number. Calculates how many different symbol triangles have the same number of "+" and "-". The 1 symbol triangles at N=7 are as follows:
+ + - + - + +
+ - - - - +
- + + + -
- + + -
- + -
- -
+
Input1 positive integers per line n <=24,n=0 exit.
Outputthe number of n and symbol triangles.
Sample Input the - + -0
Sample Output189651603275759984
This problem is to try to find the regular, find 4, found should be no regular, online look, said is can play table, haha, hit the table of the topic I have not done, did, quite fun.
The table, that is, DFS (or other means) to find out all the situation, to see which conditions meet the requirements of test instructions, it is recorded, with an array of storage, and then in the program directly to the array written up, very cool.
My playing Table program:
1#include <cstdio>2#include <cstring>3 Const intmaxn= -;4 intA[MAXN][MAXN];5 intN;6 intans,add,sub;7 voidDFS (intCNT)8 {9 if(cnt==n+1)Ten { One for(inti=n-1;i>0; i--) A { - for(intj=1; j<=i;j++) - { thea[i][j]=a[i+1][j]^a[i+1][j+1]; - } - } -Sub=add=0; + for(intI=1; i<=n;i++) - { + for(intj=1; j<=i;j++) A if(a[i][j]==1) atsub++; - Else -add++; - } - if(add==sub) -ans++; in return ; - } to for(intI=0; i<=1; i++) + { -a[n][cnt]=i; theDFS (cnt+1); * } $ }Panax Notoginseng intMain () - { the while(SCANF ("%d",&N)) + { Amemset (a,-1,sizeof(a)); theans=0; +DFS (1); -printf"%d\n", ans); $ } $ return 0; -}
My code to play the table
1#include <cstdio>2 inta[ -]={0,0,0,4,6,0,0, A, +,0,0,171,410,0,0,1896,5160,0,0,32757,59984,3 0,0,431095,822229};4 intMain ()5 {6 intN;7 while(SCANF ("%d",&N))8 {9 if(n==0)Ten Break; Oneprintf"%d%d\n", N,a[n]); A } - return 0; -}
My submission Code
HDU2510 symbol Triangle DFS direct hit table