首页 > 代码库 > 【HDOJ】2510 符号三角形

【HDOJ】2510 符号三角形

暴力打表。

 1 #include <cstdio> 2 int a[25]={0,0,0,4,6,0,0,12,40,0,0,171,410,0,0,1896,5160,0,0,32757,59984,0,0,431095,822229}; 3 int main() { 4     while (scanf("%d",a)!=EOF && *a) 5         printf("%d %d\n", *a, a[*a]); 6     return 0; 7 } 8 /* 9 #include <cstdio>10 #include <cstdlib>11 #include <cstring>12 13 // ‘+‘:1 ‘-‘:014 #define MAXN 2515 char a[MAXN];16 char map[MAXN][MAXN];17 int ans;18 19 void f(int i, int n) {20     int j;21 22     if (i == n) {23         int x, y;24 25         x = y = 0;26         for (i=0; i<n; ++i) {27             map[0][i] = a[i];28             if (a[i])29                 ++x;30             else31                 ++y;32         }33         for (i=1; i<n; ++i) {34             for (j=0; j<n-i; ++j) {35                 if (map[i-1][j] ^ map[i-1][j+1]) {36                     map[i][j] = 0;37                     ++y;38                 } else {39                     map[i][j] = 1;40                     ++x;41                 }42             }43         }44 45         if (x == y)46             ++ans;47     } else {48         for (j=0; j<2; ++j) {49             a[i] = j;50             f(i+1, n);51         }52     }53 }54 55 int main() {56     int i;57 58     for (i=1; i<MAXN; ++i) {59         ans = 0;60         memset(a, 1, sizeof(a));61         f(0, i);62         printf("%d\n", ans);63     }64 65     return 0;66 }67 */

 

【HDOJ】2510 符号三角形