Ural 1018 树dp
来源:互联网 发布:python正态分布随机数 编辑:程序博客网 时间:2024/04/28 08:50
PRO IS HERE
树dp:
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<set>#include<queue>#include<map>using namespace std;#define PB push_back#define INS insert#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define nMax 201#define bug puts("Fuck");int dp[nMax][nMax];int son[nMax];int first[nMax],nxt[nMax],fa[nMax],w[nMax],to[nMax],e,vis[nMax];void addedge(int u,int v,int f){to[e]=v;fa[e]=u;w[e]=f;nxt[e]=first[u];first[u]=e;e++;to[e]=u;fa[e]=v;w[e]=f;nxt[e]=first[v];first[v]=e;e++;}int Q,n,ans;void dfs(int u){son[u]=1;vis[u]=1;for(int i=first[u];i!=-1;i=nxt[i])if(!vis[to[i]]) {dfs(to[i]);son[u]+=son[to[i]];}return ;}void DP(int u){for(int i=0;i<=Q;i++) dp[u][i]=0;vis[u]=1;for(int i=first[u],v;i!=-1;i=nxt[i])if(!vis[v=to[i]]){DP(v);for(int j=Q;j>=1;j--) {for(int k=0;k<j;k++) dp[u][j] = max(dp[u][j],dp[v][k] + w[i] + dp[u][j-k-1]);}}//ans = max(ans,dp[u][Q]);}int main(){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);while(~scanf("%d%d",&n,&Q)){memset(first,-1,sizeof(first));e=0;ans = 0;for(int i=1,u,v,f;i<n;i++) {scanf("%d%d%d",&u,&v,&f);addedge(u,v,f);}memset(vis,0,sizeof(vis));DP(1);printf("%d\n",dp[1][Q]);}return 0;}
- Ural 1018 树dp
- Ural - 1018 纠结的树型DP...
- [ural 1018]Binary Apple Tree[树DP]
- 【树状DP】ural 1018
- ural 1018(树形dp)
- URAL - 1018 (树形dp 水题)
- Ural 1018 Binary Apple Tree 树形dp
- 第一道树形dp ural 1018
- URAL 1018 (金典树形DP)
- URAL 1018 Binary Apple Tree (树形DP)
- URAL 1018 Binary Apple Tree (树形DP)
- ural 1018-Binary Apple Tree【树状DP】
- Ural 1018 Binary Apple Tree [树形dp]
- ural 1002 Phone Numbers 字典树+dp
- ural 1002 Phone Numbers 字典树+dp
- ural 1018 Binary Apple Tree(树形DP)建二叉树
- ural 1119【dp+精度】
- 【DP】ural 1017
- group by 在sqlserver与oracle中的差别
- C++代码评审(Code Review)等级标准
- 微信绝对不收费
- extern "C"的用意
- hdu1599 无向图最小环
- Ural 1018 树dp
- (2)MySQL 三范式
- 高斯模糊、径向缩放模糊
- Oracle 客户端乱码的设置
- 内核源代码下的层次目录
- 软件配置管理(Software Configuration Management,SCM)
- 《鸟哥的linux私房菜 基础篇》第八章读书笔记(下)
- Makefile中常用的函数(一)
- word2007中怎么样快速打出箭头