hdu1054Strategic Game(树形DP)
归属简单树形DP 挺简单的 跟第一道一样 就是我跑偏了题意。。以为要覆盖点 纠结啊 推了N久 推不出啊 然后就郁闷了 打了局游戏 边想边打 实在想不出 看下题解 跑偏了
分两种情况D 方程见代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 using namespace std; 7 #define N 2010 8 int f[N]; 9 struct node 10 { 11 int f,ch,m1,m0,br; 12 void init() 13 { 14 f = m0 =ch = br =0; 15 m1 = 1; 16 } 17 }tr[N]; 18 void dfs(int u) 19 { 20 int child = tr[u].ch; 21 while(child) 22 { 23 dfs(child); 24 tr[u].m1+=min(tr[child].m0,tr[child].m1); 25 tr[u].m0+=tr[child].m1; 26 child = tr[child].br; 27 } 28 } 29 int main() 30 { 31 int i,j,n,u,m,v; 32 while(scanf("%d",&n)!=EOF) 33 { 34 memset(f,0,sizeof(f)); 35 for(i = 1; i <= n ; i++) 36 { 37 scanf("%d:(%d)",&u,&m); 38 u++; 39 if(!f[u]) 40 tr[u].init(); 41 for(j = 1; j <= m ; j++) 42 { 43 scanf("%d",&v); 44 v++; 45 tr[v].init(); 46 tr[v].f = u; 47 tr[v].br = tr[u].ch; 48 tr[u].ch = v; 49 f[v] = 1; 50 } 51 } 52 for(i = 1; i <= n ; i++) 53 { 54 if(!f[i]) 55 break; 56 } 57 dfs(i); 58 cout<<min(tr[i].m0,tr[i].m1)<<endl; 59 } 60 return 0; 61 }