HDU 1693 Eat the Trees

时间:2023-09-14 22:42:02

第一道(可能也是最后一道)插头dp。。。。

总算是领略了它的魅力。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long t,n,m,map[][],dp[][][(<<)+];
void work(long long x)
{
scanf("%I64d%I64d",&n,&m);
for (long long i=;i<=n;i++)
for (long long j=;j<=m;j++)
scanf("%I64d",&map[i][j]);
memset(dp,,sizeof(dp));
dp[][m][]=;
for (long long i=;i<=n;i++)
{
for (long long j=;j<(<<m);j++) dp[i][][j<<]=dp[i-][m][j];
for (long long j=;j<=m;j++)
for (long long k=;k<(<<(m+));k++)
{
long long r1=(<<(j-)),r2=(<<j);
if (map[i][j])
{
if ((k&r1) && (k&r2)) dp[i][j][k]=dp[i][j-][k^r1^r2];
else if ((!(k&r1)) && (!(k&r2))) dp[i][j][k]=dp[i][j-][k+r1+r2];
else dp[i][j][k]=dp[i][j-][k]+dp[i][j-][k^r1^r2];
}
else
{
if ((!(k&r1)) && (!(k&r2))) dp[i][j][k]=dp[i][j-][k];
else dp[i][j][k]=;
}
}
}
printf("Case %I64d: There are %I64d ways to eat the trees.\n",x,dp[n][m][]);
}
int main()
{
scanf("%I64d",&t);
for (long long i=;i<=t;i++)
work(i);
return ;
}