URAL1018. Binary Apple Tree】的更多相关文章

题目大概说一棵n结点二叉苹果树,n-1个分支,每个分支各有苹果,1是根,要删掉若干个分支,保留q个分支,问最多能保留几个苹果. 挺简单的树形DP,因为是二叉树,都不需要树上背包什么的. dp[u][k]表示以u结点为根的子树保留k个分支最多能有的苹果数 转移就是左子树若干个,右子树若干个转移.. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define MAXN…
组队赛的时候的一道题,那个时候想了一下感觉dp不怎么好写呀,现在写了出来,交上去过了,但是我觉得我还是应该WA的呀,因为总感觉dp的不对. #pragma warning(disable:4996) #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<string> #include<vector> #define max…
链接 简单树形DP #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> using namespace std; #define INF 0xfffffff ][]; ][]; ][]; int dfs(int pre,int u,int s) { int i; ) return dp[u][s]; ,cc[];…
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> using namespace std; ; int dp[maxn][maxn]; //dp[i][j]表示以i为根,保留j个点的最大权值. int N,Q; int G[maxn][maxn]; int num[maxn]; //以i为根的树的节点个数. //这里…
CJOJ 1976 二叉苹果树 / URAL 1018 Binary Apple Tree(树型动态规划) Description 有一棵苹果树,如果树枝有分叉,一定是分2叉(就是说没有只有1个儿子的结点)这棵树共有N个结点(叶子点或者树枝分叉点),编号为1-N,树根编号一定是1.我们用一根树枝两端连接的结点的编号来描述一根树枝的位置.现在这颗树枝条太多了,需要剪枝.但是一些树枝上长有苹果. 给定需要保留的树枝数量,求出最多能留住多少苹果.下面是一颗有 4 个树枝的树. 2 5 \ / 3 4…
Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a binary tree, i.e. any biparous branch splits up to exactly two new branches. We will enumerate by integers the root of binary apple tree, points of branch…
Binary Apple Tree Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ID: 101864-bit integer IO format: %lld      Java class name: (Any)     Let's imagine how apple tree looks in binary computer world. You're right,…
1018. Binary Apple Tree Time limit: 1.0 secondMemory limit: 64 MB Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a binary tree, i.e. any biparous branch splits up to exactly two new branches. We will enu…
http://vjudge.net/problem/17662 loli蜜汁(面向高一)树形dp水题 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct nodeTreeDP { struct node {int nxt, to, w;} E[203]; int n, q, cnt, point[103], apple[103], left[103], ri…
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1018 Dynamic Programming. 首先要根据input建立树形结构,然后在用DP来寻找最佳结果.dp[i][j]表示node i的子树上最多保存j个分支的最佳结果.代码如下: #include <iostream> #include <math.h> #include <stdio.h> #include <cstdio> #incl…