P2016 strategy game - tree DP flood problem

P2016 strategy game

Tree DP entry to the bar (now do not understand how a blue label);

Note that saw each side instead of each point (because this wrong several times);

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=3010;
int pre[maxn],last[maxn],other[maxn],l;

void add(int x,int y)
{
    l++;
    pre[l]=last[x];
    last[x]=l;
    other[l]=y;
}

int n;
int f[maxn][2];

void dfs(int x,int fa)
{
    f[x][1]=1;f[x][0]=0;
    for(int p=last[x];p;p=pre[p])
    {
        int v=other[p];
        if(v==fa) continue;
        dfs(v,x);
        f [x] [ 1 ] + = min (F [v] [ 0 ], F [v] [ 1 ]);
        f[x][0]+=f[v][1];
    }
}

int main ()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x,k,y; 
        scanf("%d%d",&x,&k);
        x++;
        for(int j=1;j<=k;j++) 
        {
            scanf("%d",&y);
            and ++ ;
            add(x,y);
            add(y,x);
        }
    }
    dfs(1,0);
    printf("%d",min(f[1][1],f[1][0]));
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/WHFF521/p/11756615.html