기호 삼각형

4178 단어 돌 이 켜 보다HDU
기호 삼각형
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 664    Accepted Submission(s): 320
Problem Description
기호 삼각형 의 첫 번 째 줄 에는 n 개의 '+' 와 '-' 로 구 성 된 기호 가 있 는데, 이후 각 줄 의 기 호 는 상행 보다 1 개가 적 고, 2 개의 같은 번호 아래 는 '+' 이 며, 2 개의 다른 번호 아래 는 '-' 이다. 몇 개의 서로 다른 기호 삼각형 이 있 는 지 계산 하여 '+' 와 '-' 의 개 수 를 같다. n = 7 시의 1 개의 기호 삼각형 은 다음 과 같다.
+ + - + -++ 
+ - - - - + 
-++ + - 
-++ - 
- + - 
- - 
+
 
Input
줄 당 1 개의 정수 n < 24, n = 0 으로 종료 합 니 다.
 
Output
n 과 기호 삼각형 의 개수. 
 
Sample Input
 
   
15 16 19 20 0
 

Sample Output
 
   
15 1896 16 5160 19 32757 20 59984
 

Source
ECJTU 2008 Autumn Contest
 

Recommend
lcy
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include
#define rep(i,s,e) for(int i = (s);i<=(e);++i)
#define maxn 100100
#define INF 1000000000
using namespace std;
/*
//             
//   - 1+ 0(        )
//           。。。     
//           :n=1 => p[1][1]
//n=2 =>p[1][2] + p[1][1]( n=1    ) => p[2][2]
//      for    p[1][n]                 ( for              )
//        。。。。。。
int cnt;
int p[30][30];//p[i][j]     i  j    
int Count[30];
void dfs(int n)
{
    if(n>24)
    {
        return ;
    }
    else
    {
        for(int i = 0;i<2;++i)//       + -
        {
            p[1][n] = i;//         i(0 + ,1 -)
            cnt += i ;//       

            for(int j = 2;j<=n;++j)
            {
              //                               
              //            (                 !!!!!!)
                p[j][n-j+1] = p[j-1][n-j+1]^p[j-1][n-j+2];//      
                cnt += p[j][n-j+1];
            }

            if(n*(n+1)/2==cnt*2)
            Count[n]++;

            dfs(n+1);
            //               (              +   -)
            for(int j = 2;j<=n;++j)
            {
                cnt -= p[j][n-j+1];
            }
            cnt -= i;

        }
    }
}


int main()
{
    memset(Count,0,sizeof(Count));
    //memset(p,0,sizeof(p));
    cnt  = 0;
    dfs(1);
    for(int i = 1;i<=24;++i)
    printf("%d
",Count[i]); }*/ // 。。 。。。 int result[24]={0,0,4,6,0,0,12,40,0,0,171,410,0,0,1896,5160,0,0,32757,59984,0,0,431095,822229}; int main() { int n; cin>>n; while(n!=0) { cout<>n; } return 0; }

좋은 웹페이지 즐겨찾기