LA 4987 背包】的更多相关文章

题意: 有n个施工队,给定他们的位置,有m个防空洞,给定位置,求将施工队放到m个防空洞里面,最少的总距离? n<=4000 分析: dp[i][j] 前 i 个施工队,放到前 j 个防空洞里面的最少距离: dp(i+1,j) = min(dp(i,j),dp(i,j-1)) + dist(a[i] - b[j]): DP采用滚动数组: 那么,第二维的防空洞该怎么循环呢? 因为,每个防空洞都要有,那么这类似于背包中的容量,刷表的方式: #include <bits/stdc++.h> us…
题目链接:https://vjudge.net/contest/164840#problem/D 题意: 给一棵树,每条边上有一些权值,求 长度不超过 x ,最多能走多少个点: 分析: 考虑每一个节点,他可以一直走下去,也可以走回来而走到他的兄弟节点: 状态定义: d[x][j][0/1] 从 i 出发,走 j 个节点的最短距离: 1.回来,这就是一个背包,更新当前节点: 2.不回来,则是要考虑从哪个部分不回来: #include <bits/stdc++.h> using namespace…
zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 757    Accepted Submission(s): 282 Problem Description As one of the most powerful brushes in the world, zhx usually takes part in…
传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 145    Accepted Submission(s): 49 Problem Description As one of the most powerful brushes in the world, zhx usually takes part…
Problem Description As one of the most powerful brushes in the world, zhx usually takes part in all kinds of contests. One day, zhx takes part in an contest. He found the contest very easy for him. There are n problems in the contest. He knows that h…
###题面 https://www.lydsy.com/JudgeOnline/problem.php?id=4987 ###分析 先考虑贪心,显然k个节点形成一棵树 求出树的直径,显然直径应该只被经过1次(最长的边应该走最少次数),其他非直径上的边被经过2次 整体的形状应该类似一条链上接着许多子树 考虑树形DP 子状态:dp[x][i][j](j∈{0,1,2})dp[x][i][j]( j\in \left\{0,1,2\right\})dp[x][i][j](j∈{0,1,2}),表示以x…
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4987 题解 一道还不错的题咯. 很容易发现一个结论:这 \(k\) 个点构成的一定是一个连通块,并且走的时候应该是按照某种类似于 dfs 的遍历方式连续走的. 可以发现,最终答案应该有:从根的某个子树走出来,到某个子树中去的这样的情况,也有可能是从根到某个子树中去的情况:同时,过程中会用到从根到子树中走一遍再回到根的情况.这三种情况都需要考虑. 于是进行树形 dp,令 \(dp[x][i][…
J - 10 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 5234 Description Today is Gorwin’s birthday. So her mother want to realize her a wish. Gorwin says that she wants to eat many cakes. Thus,…
Description A set of frogs have accidentally fallen to the bottom of a large pit. Their only means of escaping the pit is to jump out of it. Each frog i​ is described by three parameters (li, wi, hi)​ where li​ is its leap capacity, wi​ its weight, a…
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出dp[j]=min(dp[j],dp[j-a]+1).j从a到k*10000顺序枚举,因为类似于完全背包. http://train.usaco.org/usacoprob2?a=fSgPyIazooa&S=stamps /* TASK:stamps LANG:C++ */ #include<c…