Symbol triangles
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1246 Accepted Submission (s): 664
The 1th line of the problem description symbol triangle has n a symbol consisting of "+" and "-", with 1 fewer symbols per line, and 2 under the same number as "+", and 2 different numbers under "-". Calculates how many different symbol triangles have the same number of "+" and "-". The 1 symbol triangles at N=7 are as follows:
+ + - + - + +
+ - - - - +
- + + + -
- + + -
- + -
- -
+
Input 1 positive integers per line n <=24,n=0 exit.
The number of outputn and symbol triangles.
Sample Input151619200 Sample Output15 189616 516019 3275720 59984 play the table code:
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 inta[ -];6 Charres[ -][ -];7 intsum;8 BOOLCountintN)9 {Ten intp1=0, p2=0; One inti,j; A for(i=1; i<=n;i++) - { - if(res[0][i]=='+') p1++; the Elsep2++; - } - for(intI=1; i<n;i++) - for(j=1; j<=n-i;j++) + { -Res[i][j]= (res[i-1][j]==res[i-1][j+1]?'+':'-'); + if(res[i][j]=='+') p1++; A Elsep2++; at } - if(p1==p2) - return 1; - return 0; - } - voidDfsintNints) in { - inti,j; to if(s>N) + { - if(count (n)) thesum++; * return; $ }Panax Notoginsengres[0][s]='+'; -DFS (n,s+1); theres[0][s]='-'; +DFS (n,s+1); A return; the } + intMain () - { $ intN; $ inti,j; -a[1]=a[2]=0; - for(i=1; i<= -; i++) the { -sum=0;WuyiDFS (I,1); thea[i]=sum; -cout<<a[i]<<Endl; Wu } -}
Symbol triangle (hdu 2510 search + hit table)