POJ 2342 tree DP entry question, poj2342
There is a celebration party for the university. I want to invite some people who work in the university to attend the gala. Everyone has their own funny values. But now I have a problem that if there is a direct relationship between the two people, so only one of them can come to participate, please come to some people, the maximum funny value is.
Tree DP entry question.
DP section:
Dp [I] [0] indicates that employee I does not come to the party. The maximum funny value of the subtree with I as the root is,
Dp [I] [1] indicates the maximum funny value of the subtree where staff I come to the party.
Transfer equation:
Dp [cur] [1] + = dp [next] [0];
Dp [cur] [0] + = Max (dp [next] [1], dp [next] [0]);
#include "stdio.h"#include "string.h"#include "vector"using namespace std;struct node{ int fa; vector<int>child;}data[6010];int dp[6010][2],vis[6010];int Max(int a,int b){ if (a<b) return b;else return a;}void dfs(int cur){ int i,next; vis[cur]=1; for (i=0;i<data[cur].child.size();i++) { next=data[cur].child[i]; if (vis[next]==0) dfs(next); dp[cur][1]+=dp[next][0]; dp[cur][0]+=Max(dp[next][1],dp[next][0]); }}int main(){ int n,i,a,b; while (scanf("%d",&n)!=EOF) { memset(dp,0,sizeof(dp)); memset(data,0,sizeof(data)); memset(vis,0,sizeof(vis)); for (i=1;i<=n;i++) scanf("%d",&dp[i][1]); while(scanf("%d%d",&a,&b)) { if (a+b==0) break; data[a].fa=b; data[b].child.push_back(a); } for (i=1;i<=n;i++) if (data[i].fa==0) { dfs(i); break; } printf("%d\n",Max(dp[i][1],dp[i][0])); } return 0;}
What are the types of Dynamic Planning for noip (improving group difficulty? (For example, coordinate DP and backpack DP) What are their classic questions?
Tree-like dp, interval type, line type, backpack, State compression, quadrilateral inequality optimization, etc.
There are many questions in poj classification.
: Solve the path planning problem rob. It is best to give pascal or c ++ a standard path.
I think this question is a tree-like DP
The dynamic return equation can be expressed using f [I, J, K ].
I indicates vertex I
When j requests come in k
But there are many restrictions
But is there any solution that should be pretty good?
We have read this question and have no good conclusions.
There was a solution for the super Ox a few years ago,
But cannot find .....