HDU 1693 Eat the Trees

Posted ziliuziliu

tags:

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

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

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

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

 

以上是关于HDU 1693 Eat the Trees的主要内容,如果未能解决你的问题,请参考以下文章

HDU 1693 Eat the Trees

HDU1693Eat the Trees(插头dp)

HDU1693 Eat the Trees(zerojudge a228)

HDU1693 Eat the Trees

hdu1693 Eat the Trees 插头dp

[Hdu 1693] Eat the Trees 轮廓线DP