标签:des style blog http color os
| Time Limit: 2000MS | Memory Limit: 10000K | |
| Total Submissions: 6105 | Accepted: 2808 |
Description

Input
Output
Sample Input
4 0:(1) 1 1:(2) 2 3 2:(0) 3:(0) 5 3:(3) 1 4 2 1:(1) 0 2:(0) 0:(0) 4:(0)
Sample Output
1 2
Source
//6508K 375MS
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define M 1507
using namespace std;
int head[M],nodes;
int dp[M][M];
struct E
{
int v,next;
}edge[M*M];
void addedge(int u,int v)
{
edge[nodes].v=v;edge[nodes].next=head[u];
head[u]=nodes++;
}
void DP(int u,int p)
{
dp[u][0]=1;
dp[u][1]=0;
int k,v;
for(k=head[u];k!=-1;k=edge[k].next)
{
v=edge[k].v;
if(v==p)continue;
DP(v,u);
dp[u][0]+=min(dp[v][0],dp[v][1]);
dp[u][1]+=dp[v][0];
}
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(head,-1,sizeof(head));
nodes=0;
int u,k,v;
for(int i=0;i<n;i++)
{
scanf("%d:(%d)",&u,&k);
while(k--)
{
scanf("%d",&v);
addedge(u,v);
addedge(v,u);
}
}
DP(0,0);
printf("%d\n",min(dp[0][0],dp[0][1]));
}
return 0;
}
POJ 1463 Strategic game 最小点覆盖集(树形dp),码迷,mamicode.com
POJ 1463 Strategic game 最小点覆盖集(树形dp)
标签:des style blog http color os
原文地址:http://blog.csdn.net/crescent__moon/article/details/24735429