ZOJ 3623 —— Battle Ships(DP)
来源:互联网 发布:淘宝网迷你冰箱 编辑:程序博客网 时间:2024/05/29 17:39
题目:Battle Ships
题意:攻打一座生命为L的塔,我方可以生产N种战舰,第i中战舰的生产需要时间ti,它每秒可以对塔造成li的伤害。一开始没有战舰,然后每秒我方可以选择生产任意一种战舰,或是不行动。战舰每秒都会攻击塔,当塔的生命小于等于0时获胜。现在要求获胜的最小时间。
由于对方生命L最多330,考虑到攻击力超过L时效果等同于L,所以攻击力我们也可以认为上限330,以对方生命和我方攻击力为状态进行动态规划。
dp[i][j]表示对方生命为i,我方攻击力为j的用时。
初始状态dp[L][0]=0,目标状态min(dp[0][j]),1<=j<=L。
状态转移的时候选择一种战舰进行生产然后转移,注意转移的时候要记得加上生产过程其他战舰造成的伤害。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N = 31;const int M = 331;const int INF = 0x7fffffff;int dp[M][M];int n, m, w[N], v[N];int main(){ while(~scanf("%d %d", &n, &m)){ for(int i=0; i<n; i++) scanf("%d %d", w+i, v+i); for(int i=0; i<=m; i++){ for(int j=0; j<=m; j++){ dp[i][j]=INF; } } dp[m][0]=0; for(int i=m; i>0; i--){ for(int j=0; j<=m; j++){ if(dp[i][j]==INF) continue; int nl = max(0, i-j); dp[nl][j] = min(dp[nl][j], dp[i][j]+1); for(int k=0; k<n; k++){ nl = max(0, i - j * w[k]); int nv = min(j+v[k], m); dp[nl][nv] = min(dp[nl][nv], dp[i][j]+w[k]); } } } int ans = INF; for(int i=0; i<=m; i++) ans = min(ans, dp[0][i]); printf("%d\n", ans); } return 0;}
0 0
- ZOJ 3623 —— Battle Ships(DP)
- zoj 3623 Battle Ships(dp)
- ZOJ 3623 Battle Ships(dp)
- zoj 3623 Battle Ships dp
- 【神DP】-ZOJ-3623-Battle Ships
- ZOJ 3623 Battle Ships 简单DP
- ZOJ 3623 Battle Ships
- zoj 3623 Battle Ships
- ZOJ 3623 Battle Ships
- ZOJ 3623 Battle Ships
- ZOJ 3623 Battle Ships
- zoj 3623 battle ships
- ZOJ 3623 Battle Ships
- ZOJ 3623 Battle Ships (完全背包)
- ZOJ - 3623 - Battle Ships (01背包变形)
- ZOJ 3623 Battle Ships(完全背包)
- ZOJ 3623 - Battle Ships(完全背包)
- ZOJ Problem Set - 3623Battle Ships
- OpenCV基础篇——图形图像旋转
- switch内部的变量定义
- JVM性能优化:垃圾收集
- 在非主线程里处理bitmap
- 长按手势删除tableView选中的行
- ZOJ 3623 —— Battle Ships(DP)
- XDOJ1229 - A Game
- OpenCV基础篇之像素访问
- Objective-C——消息、Category和Protocol
- Linux线程属性
- Http状态代码
- UVA 11796Dog Distance
- 使用Pspice进行电路仿真
- 垃圾收集算法