入门插头dp,终于知道什么叫插头dp了。。。看了一下,陈丹琦的论文,然后又去sha崽哪儿逛了一圈。。。不过虽然是最简单的插头dp,要是自己写的话难度还是很大啊。。。看了一下大牛们的代码才写出来的。。。
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 13;
LL dp[N][N][1 << N];
int g[N][N];
int main()
{
int t, n, m, i, j, k, s, cas = 1, p, q;
bool l, u;
scanf("%d", &t);
while(t --)
{
scanf("%d%d", &n, &m);
for(i = 1; i <= n; i ++)
{
for(j = 1; j <= m; j ++)
{
scanf("%d", &g[i][j]);
}
}
CLR(dp, 0);dp[0][m][0] = 1;
for(i = 1; i <= n; i ++)
{
for(j = 0; j < (1 << m); j ++)
dp[i][0][j << 1] = dp[i - 1][m][j];
for(j = 1; j <= m; j ++)
for(k = 0; k < (1 << m << 1); k ++)
{
p = 1 << j;
q = p >> 1;
u = k & p;
l = k & q;
if(g[i][j])
{
dp[i][j][k] = dp[i][j - 1][k ^ p ^ q];
if(l != u) dp[i][j][k] += dp[i][j - 1][k];
}
else
{
if(u || l) dp[i][j][k] = 0;
else dp[i][j][k] = dp[i][j - 1][k];
}
}
}
printf("Case %d: There are %I64d ways to eat the trees.\n", cas ++, dp[n][m][0]);
}
}
分享到:
相关推荐
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
杭电ACMhdu1163
HDU1059的代码
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
ACM HDU题目分类,我自己总结的大概只有十来个吧
hdu 1166线段树代码
HDU最全ac代码
自己做的HDU ACM已经AC的题目
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105. Input Input...
hdu动态规划算法集锦
hdu题目分类
HDU图论题目分类
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码