[Hdu 1693] Eat the Trees 轮廓线DP

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Hdu 1693] Eat the Trees 轮廓线DP相关的知识,希望对你有一定的参考价值。

题意

  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的主要内容,如果未能解决你的问题,请参考以下文章

HDU1693 Eat the Trees(zerojudge a228)

HDU1693 Eat the Trees

hdu1693 Eat the Trees 插头dp

HDU 1693 Eat the Trees (插头DP)

Eat the Trees(hdu 1693)

[Hdu 1693] Eat the Trees 轮廓线DP