ZOJ 2972 Hurdles of 110m 【DP 背包】】的更多相关文章

一共有N段过程,每段过程里可以选择 快速跑. 匀速跑 和 慢速跑 对于快速跑会消耗F1 的能量, 慢速跑会集聚F2的能量 选手一开始有M的能量,即能量上限 求通过全程的最短时间 定义DP[i][j] 为跨越第 i 个栏,剩余 j 点能量 动态转移方程 dp[i][j] = min(dp[i][j], dp[i-1][j-F1]+T1) (Fast Mode) dp[i][j] = min(dp[i][j], dp[i-1][j]+T2) (Normal Mode) dp[i][j] = min(…
题目:110米栏,运动员能够用三种状态跑,1状态耗体力且跑得快,2状态不消耗体力,3状态恢复体力且跑得慢. 体力上限是M,且初始满体力,如今想知到最小的时间跑全然程. 分析:dp,全然背包.题目是一个物品体积可能为负数的背包,求背包就可以. 只是,由于物品体积可能是负数,所以无论哪个方向背包都有后效性,直接用二维避免后效性. 转移方程:F(i,j)= min(F(i-F1,j)+ T1,F(i-1,j)+ T2,F(i+F2,j)+T3). 说明:(2011-09-19 01:23). #inc…
描述 In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well. Liu Xiang is one of the famous Olympic athletes in China. I…
题目 简单的dp,但是我还是参考了网上的思路,具体我没考虑到的地方见代码 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> using namespace std; #define inf 2100000000 //int min(int a,int b) //{ // return a<b? a:b; //} int main() { int t,i…
题目描述 Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Farmer John would like to milk as many of his N (1 <= N <= 1,000) cows as possible. If the milked cows carry more than K (1 <= K <= D) different d…
这个题目给定一棵树,以及树的每个树枝的苹果数量,要求在保留K个树枝的情况下最多能保留多少个苹果 一看就觉得是个树形DP,然后想出 dp[i][j]来表示第i个节点保留j个树枝的最大苹果数,但是在树形过程中,有点难表示转移 后来看了下大神的做法才知道其实可以用背包来模拟 树枝的去留,其实真的是个背包诶,每个子树枝就相当于物品,他占用了多少树枝量,带来多少的收益,就是用背包嘛,于是用树形DP+背包就可以做了 #include <iostream> #include <cstdio> #…
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3626 题目大意:树中取点.每过一条边有一定cost,且最后要回到起点.给定预算m,问最大价值. 解题思路: 首先要注意这题要回到起点,由于树的特殊结构(每个结点只有一个父亲)也就是说,要回到开头, 开销是2倍.所以首先m/=2. 然后就是树形背包的求解,这题的cost在边,所以for写法变成如下: for(m....j....0)     for(0....k…
#include<cstdio> #include<vector> #include<cstring> #include<iostream> using namespace std; ; vector<int>a[MAXN]; int n,m,v[MAXN],vis[MAXN],dp[MAXN][MAXN]; void dfs(int root) { dp[root][] = v[root]; vis[root] = ; int i, len =…
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1109 FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contains J…
描述 In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well. Liu Xiang is one of the famous Olympic athletes in China. I…