HDU 2159 FATE (二维背包)
题意:中文题。
析:dp[i][j] 已经杀了 i 个怪兽,已经用了 j 体积,所能获得的最大经验值,这个和一维的差不多,只是加一维而已。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e2 + 5;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int dp[maxn][maxn];
int a[maxn], c[maxn]; int main(){
int q, s;
while(scanf("%d %d %d %d", &n, &m, &q, &s) == 4){
for(int i = 0; i < q; ++i) scanf("%d %d", a+i, c+i); memset(dp, 0, sizeof dp);
int ans = -1;
for(int i = 1; i <= s; ++i){
for(int k = 0; k < q; ++k){
for(int j = c[k]; j <= m; ++j){
dp[i][j] = Max(dp[i][j], dp[i-1][j-c[k]] + a[k]);
if(dp[i][j] >= n){ ans = Max(ans, m-j); break; }
}
}
} printf("%d\n", ans);
}
return 0;
}
HDU 2159 FATE (二维背包)的更多相关文章
- HDU 2159 FATE (二维背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2159 解题报告:这题实际上是一个二维的背包问题,也可以由01背包扩展而来,01背包用一维数组,可想而知 ...
- hdu 2159 FATE (二维完全背包)
Problem Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务.久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级.现 ...
- 杭电 2159 fate(二维背包费用问题)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 2159 FATE (完全背包+有限尚需时日)()双费背包
FATE Problem Description 近期xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务.久而久之xhd開始对杀怪产生的厌恶感,但又不得不通过杀怪来升 ...
- hdu2159 Fate 二维背包
#include <cstring> #include <string> #include <cstdio> #include <cmath> #inc ...
- HDU 2159 FATE(二维费用背包)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU 2159 FATE(全然背包+二维费用背包)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU 2159 FATE(二维全然背包)
中文题目就不用解释了 就是裸的二维全然背包 d[i][j]表示消耗i忍耐杀j个怪最多可获得的经验 然后就用全然背包来做了 二维背包背包只是是多了一重循环 <span style=&quo ...
- HDU 2159 FATE (DP 二维费用背包)
题目链接 题意 : 中文题不详述. 思路 : 二维背包,dp[i][h]表示当前忍耐值为i的情况下,杀了h个怪得到的最大经验值,状态转移方程: dp[i][h] = max(dp[i][h],dp[i ...
随机推荐
- laravel 做图片的缩略图 踩坑
系统需求 PHP >= 5.3 Fileinfo Extension GD Library (>=2.0) … or … Imagick PHP extension (>=6.5.7 ...
- 11g的新特性:SQL Plan Management(SPM)
Oracle11g中,Oracle提供dbms_spm包来管理SQL Plan,SPM是一个预防机制,它记录并评估sql的执行计划,将已知的高效的sql执行计划建立为SQL Plan Baseline ...
- Tkinter Relief styles(样式)
Tkinter Relief styles: 构件的浮雕式是指某些模拟的3-D周围的部件外的影响.下面是一排按钮的屏幕截图展示了所有可能的救济风格 构件的浮雕式是指某些模拟的3-D周围的部件外 ...
- keil中结构体跨文件调用
在a.h中: 定义了, struct ABC{ short a; short b; ```}; 在a.c中(#include "a.h"): 声明了, struct ABC stc ...
- Netty简单的重连机制
其实重连机制并不是多么多高深的技术,其实就是一个在客户端做一个简单的判断,如果连接断了,那么就重新调用连接服务端的代码 当然,我们重连的动作肯定是发生在断连之后发生的,我们可以在上篇的心跳机制的基础上 ...
- 2、keys相关命令
redis的官网http://redis.io是学习redis的重要资源库,所有命令都分门别类的罗列在了这里http://redis.io/commands. 1.数据库选择命令: SELECT in ...
- C# 强制删除文件,解除占用的几点思考
有一个古老的传说: 占用的文件是可以被强制删除的... 如果被别的应用程序打开着,你就要先找到那个打开的程序,结束掉才行.或者关闭关闭相关进程,延迟的方法. 一般来说被占用就意味着有其它进行或者线程对 ...
- leetcode477
public class Solution { public int TotalHammingDistance(int[] nums) { , n = nums.Length; ; j < ; ...
- 微信小程序中this关键字使用技巧
转自:https://blog.csdn.net/qq_33956478/article/details/81348453 微信小程序中,在wx.request({});方法调用成功或者失败之后,有时 ...
- Python的输入输出
一:Python2.x版本下的输入输出 Python2.x 下的输入 1)raw_input 格式:result = raw_input("提示信息")功能:1)会等待用户输入内容 ...