HDU-2510

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<iomanip>
#define maxn 24 + 5

using namespace std;

int a[maxn + 5][maxn + 5];
int ans;
// 1 is +, 0 is -
void dfs(int deep, int n) {
    if(deep > n) {
        int cnt1 = 0, cnt2 = 0;
        for(int i = 1; i < n; i++) {
            for(int j = 1; j <= n - i; j++) {
                if(a[i][j] == a[i][j + 1])
                    a[i + 1][j] = 1;
                else a[i + 1][j] = 0;
            }
        }
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n - i + 1; j++) {
                if(a[i][j])
                    cnt1++;
                else cnt2++;
            }
        }
        if(cnt1 == cnt2)
            ans++;
        return ;
    }
    
    for(int k = 0; k <= 1; k++) {
        a[1][deep] = k;
        dfs(deep + 1, n);
    }
}

int main() {
    /*
    while(cin>>n && n != 0) {
        ans = 0;
        dfs(1);
        cout<<ans<<endl;
    }
    */
    int b[maxn];
    memset(b, 0, sizeof(b));
    for(int i = 1; i < 25; i++) {
        ans = 0;
        dfs(1, i);
        b[i] = ans;
        cout<<b[i]<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40830622/article/details/82995546
hdu