Partial Tree---hdu5534(完全背包)】的更多相关文章

题目链接: H - Partial Tree  HDU - 5534 题目大意:首先是T组测试样例,然后n个点,然后给你度数分别为(1~n-1)对应的不同的权值,然后问你在这些点形成树的前提下的所能形成的最大权值. 具体思路: 这个题是学长做的,我记录一下思路. 有点背包的感觉,但是和之前我做过的有点不同,原来的背包是互相不会影响的.但是对于这个题,我们需要的前提是形成一棵树,所以为了解决这个问题,我们先给每个点分配一个度,然后再去把剩余的n-2的度再分配下去就可以了. AC代码: #inclu…
题目链接 题意 给出一个n个结点的树,给出n-1个度的权值f[],代表如果一个点的度数为i,那么它对于答案的贡献有f[i].问在这棵树最大的贡献能达到多少. 思路 对于这个图,有n*2-2个度可以分配(看成一条链的形状),首先可以确定n个点,那么每个点都是要分配一个度的,因此现在有n个f[1],还有n-2个度没有分配.那么这n-2就可以当做背包容量,对于每一种度,像完全背包一样去枚举用多少种最优. #include <bits/stdc++.h> using namespace std; ty…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5534 题解:这题一看有点像树形dp但是树形dp显然没什么思路.然后由于这里的约束几乎没有就是一颗树然后是任意组合,但是有一点总的度数是2*n-2这是不变的,然后就是选择度数为1,2,3....n-1的点的组合,这么说说是不是有点像背包,然后可以想一下一开始所有点的度数都为1然后就是n*f[1]如果要组成一个度数为2的话只需要剪掉一个度数为1的也就是说f[1]然后加上f[2]即可,这样就很…
题目:这里 题意: 感觉并不能表达清楚题意,所以 Problem Description In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two nodes are connected by exactly one path. In other words, any connected graph without simple cycles is a…
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5534 Description In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two nodes are connected by exactly…
一棵树一共有2*(n-1)度,现在的任务就是将这些度分配到n个节点,使这n个节点的权值和最大. 思路:因为这是一棵树,所以每个节点的度数都是大于1的,所以事先给每个节点分配一度,答案 ans=f[1]*n 先将答案赋值 所以接下来研究的就是,将剩下的n-2个度分配 即分别看 分配度数为1到n-2的节点的有几个(因为每个节点已经有一度),然后因为每个节点都加上了权值f[1],所以这时f[2]=f[2]-f[1],以此类推, 看到这里,就是一个完全背包问题:如果还没看出来,详细一点 有1到n-2这些…
Partial Tree In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two nodes are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. You find a partial tree o…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 126    Accepted Submission(s): 68 Problem Description In mathematics, and more specifically in graph theory, a tree is an undirected graph in w…
Partial Tree 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 完全背包 做这题前去学习了下完全背包,觉得这个优化简直神技!(以前都是用01背包做的,数据水的话可以过= =) ;i<=n;++i) for(int j=i;j<=V;++j) dp[j]=max(dp[j],dp[j-i]+v[i]); 完全背包 时间复杂度O(VE) 我们回到这道题,显然整棵树的总的度为2n-2,相当于将2n-2个度分配到n个结点中去: 为了保证…
Partial Tree http://acm.hdu.edu.cn/showproblem.php?pid=5534 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description In mathematics, and more specifically in graph theory, a tree…