HDU2510 symbol Triangle DFS direct hit table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.