|洛谷|动态规划|P1156 垃圾陷阱
来源:互联网 发布:打淘宝客服要话费吗 编辑:程序博客网 时间:2024/05/01 14:00
http://www.luogu.org/problem/show?pid=1156
用布尔数组f[i][j]表示高度为i时体力值为j时的状态存在
然后DP即可
#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#define ms(i,j) memset(i,j, sizeof i);using namespace std;struct ab{int t;int f;int h;}G[105];int d,g;bool f[405][6005];bool cmp (const ab &a, const ab &b){return a.t<b.t;}int main(){int s = 10;scanf("%d%d", &d, &g);for (int i=1;i<=g;i++){scanf("%d%d%d", &G[i].t, &G[i].f, &G[i].h);s += G[i].f;}sort(G+1, G+1+g, cmp);ms(f, false);f[0][10] = true;for (int i=1;i<=g;i++)for (int j=d-1;j>=0;j--)for (int k=s;k>=G[i].t;k--){if (f[j][k]){f[j+G[i].h][k] = true;if (j+G[i].h>=d){printf("%d\n", G[i].t);return 0;}f[j][k+G[i].f] = true;}}for (int i=s;i>=0;i--){if (f[0][i]) {printf("%d\n", i);break;} } return 0;}
0 0
- |洛谷|动态规划|P1156 垃圾陷阱
- 洛谷P1156 垃圾陷阱
- 洛谷 P1156 垃圾陷阱
- 洛谷P1156 垃圾陷阱
- 洛谷【P1156】垃圾陷阱
- 洛谷 P1156 垃圾陷阱
- 洛谷 P1156 垃圾陷阱
- 洛谷p1156垃圾陷阱
- 洛谷 [P1156] 垃圾陷阱
- 【DP】洛谷 P1156 垃圾陷阱
- 洛谷P1156 垃圾陷阱 背包DP
- P1156 垃圾陷阱
- P1156 垃圾陷阱
- 洛谷P1156 垃圾陷阱(DP,0-1背包)
- 【动态规划】[luoguP1156]垃圾陷阱
- P1156 垃圾陷阱(dp)有待理解
- 洛谷P1156
- 洛谷1156 垃圾陷阱
- Division (斜率dp)
- 面试题:两个对象值相同(x.equals(y) == true),但却可有不同的hash code,这句话对不对?
- 2016四川省赛 Floyd-Warshall
- [LeetCode]--67. Add Binary
- Linux 时钟模块分析2
- |洛谷|动态规划|P1156 垃圾陷阱
- framebuffer简介与应用
- Cache-Control no-cache与max-age=0的区别
- 机器学习笔记(十五)——HMM序列问题和维特比算法
- HDU 2031 进制转换
- BZOJ2093[Poi2010] Frog
- 【Maven实战】05 依赖
- Java笔试面试题二(常考问答)
- Linux下的shell编程(五)--循环