hdu1693

时间:2022-10-04 20:46:51

题解:

还是插头dp

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int gp[][],n,m;
long long dp[][][<<];
void DP()
{
memset(dp,,sizeof(dp));
dp[][m][]=;
for (int i=;i<=n;i++)
{
for (int j=;j<(<<m);j++)dp[i][][(j<<)]=dp[i-][m][j];
for (int k=;k<=m;k++)
{
for(int sta=;sta<(<<(m+));sta++)
{
int y=<<k;
int x=<<(k-);
if (gp[i][k])
{
if((sta&x)!=&&(sta&y)!=)dp[i][k][sta]=dp[i][k-][sta-x-y];
else if((sta&x)==&&(sta&y)==)dp[i][k][sta]=dp[i][k-][sta+x+y];
else dp[i][k][sta]=dp[i][k-][sta^x^y]+dp[i][k-][sta];
}
else
{
if ((sta&x)==&&(sta&y)==)dp[i][k][sta]=dp[i][k-][sta];
else dp[i][k][sta]=;
}
}
}
}
printf("There are %I64d ways to eat the trees.\n",dp[n][m][]);
}
int main()
{
int c,cn=;
scanf("%d",&c);
while (c--)
{
cn++;
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)scanf("%d",&gp[i][j]);
printf("Case %d: ",cn);
DP();
}
return ;
}

相关文章