poj 1192最优连通子集(简单树形dp)
2013-08-27 23:30
357 查看
题目链接:http://poj.org/problem?id=1192
View Code
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> using namespace std; const int maxn = 1005; const int INF = 0x3f3f3f; int dp[maxn]; vector<int> G[maxn]; int W[maxn]; int N; struct Point{ int x,y; }P[maxn]; int ans; void dfs(int u,int fa){ dp[u] = W[u]; for(int i=0;i<G[u].size();i++){ int v = G[u][i]; if(v == fa) continue; dfs(v,u); dp[u] += max(dp[v],0); } ans = max(ans,dp[u]); } int main() { // freopen("E:\\acm\\input.txt","r",stdin); scanf("%d",&N); for(int i=1;i<=N;i++){ scanf("%d %d",&P[i].x,&P[i].y); scanf("%d",&W[i]); } for(int i=1;i<=N;i++) for(int j=i+1;j<=N;j++) if(abs(P[i].x-P[j].x) + abs(P[i].y-P[j].y) == 1){ G[i].push_back(j); G[j].push_back(i); } ans = -INF; dfs(1,-1); printf("%d\n",ans); }
View Code
相关文章推荐
- POJ 1192 最优连通子集 (树形dp)
- poj 1192 最优连通子集(树形dp)题目好难懂。。。
- POJ-1192 最优连通子集(树形DP入门+模板)
- POJ 1192 最优连通子集【树形DP】
- POJ1192 最优连通子集(树形DP)
- POJ - 1192 最优连通子集 (树形DP)
- POJ 1192 -最优连通子集 树形DP
- POJ 1192 最优连通子集 最详细的题解 (无向树树形DP)
- poj 1192 最优连通子集 树状dp
- POJ1192最优连通子集(树状dp)
- POJ 1192 最优连通子集(树上DP)
- poj 1192 最优连通子集 树状dp
- poj 1192-最优连通子集解题报告
- poj 1192 最优连通子集
- POJ-1192 最优连通子集 动态规划
- POJ1192 树形DP 最优连通子集
- poj 1192 最优连通子集 树的孩子兄弟表示法+简单树型dp
- (树形DP) 最优连通子集(POJ1192)
- poj 1192 最优连通子集
- poj1192(记忆化搜索)最优连通子集