标签:str memcpy amp string map color inline ring define
n * m 的矩形, 有坏点, 求划分成若干个回路的方案数.
n, m <= 11 .
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cctype> 5 #define F(i, a, b) for (register int i = (a); i <= (b); i++) 6 #define LL long long 7 inline int rd(void) { 8 int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == ‘-‘) f = -1; 9 int x = 0; for (; isdigit(c); c = getchar()) x = x*10+c-‘0‘; return x*f; 10 } 11 12 int n, m, Map[12][12]; 13 LL f[4096], g[4096]; 14 15 int main(void) { 16 #ifndef ONLINE_JUDGE 17 freopen("hdu1693.in", "r", stdin); 18 #endif 19 20 for (int nT = rd(), cas = 1; cas <= nT; cas++) { 21 n = rd(), m = rd(); F(i, 1, n) F(j, 1, m) Map[i][j] = rd(); 22 int Full = (1 << m+1) - 1; 23 24 memset(f, 0, sizeof f), f[0] = 1; 25 F(i, 1, n) F(j, 1, m) { 26 memset(g, 0, sizeof g); 27 if (!Map[i][j]) { 28 F(s, 0, Full) 29 g[s] = (s & 1) || (s >> j & 1) ? 0 : f[s]; 30 } 31 else { 32 F(s, 0, Full) { 33 g[s] = f[s ^ (1 << j) ^ 1]; 34 if ((s & 1) ^ (s >> j & 1)) 35 g[s] += f[s]; 36 } 37 } 38 if (j == m) { F(s, 0, Full) if (s & 1) g[s] = 0; } 39 memcpy(f, g, sizeof g); 40 } 41 printf("Case %d: There are %lld ways to eat the trees.\n", cas, f[0]); 42 } 43 44 return 0; 45 }
[Hdu 1693] Eat the Trees 轮廓线DP
标签:str memcpy amp string map color inline ring define
原文地址:http://www.cnblogs.com/Sdchr/p/7476778.html