给定n种物品,每种物品需要ti时间生产出来,生产出来以后,每单位时间可以创造wi个价值。如果需要创造至少W个价值,求最少时间。

思路:dp[j]表示用时间j所能创造的最大价值,则有转移方程:dp[j + t[i]] = max(dp[j + t[i], dp[j] + t * w[i]])。另外是否需要按一定顺序排序呢??以下是ac代码。

 #pragma comment(linker, "/STACK:10240000,10240000")

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define rep(a, b) for (int a = 0; a < (b); a++)
#define rep1(a, b) for (int a = 1; a <= (b); a++)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pc(a) putchar(a)
#define ps(a) printf("%s", a)
#define pd(a) printf("%d", a)
#define sd(a) scanf("%d", &a) typedef double db;
typedef long long LL;
typedef pair<int, int> pii;
typedef multiset<int> msi;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii; const int dx[] = {, , , -, , , -, -};
const int dy[] = {, , -, , -, , , -};
const int maxn = 1e5 + ;
const int maxm = 1e5 + ;
const int maxv = 1e7 + ;
const int max_val = 1e6 + ;
const int MD = 1e9 +;
const int INF = 1e9 + ;
const double PI = acos(-1.0);
const double eps = 1e-; template<class T> T gcd(T a, T b) { return b == ? a : gcd(b, a % b); } int f[], a[], b[]; int main() {
//freopen("in.txt", "r", stdin);
int n, l;
while (cin >> n >> l) {
rep(i, n) {
sd(a[i]);
sd(b[i]);
}
int maxt = ;
mem0(f);
rep(i, n) {
rep(j, maxt) {
f[j + a[i]] = max(f[j + a[i]], f[j] + j * b[i]);
}
}
int ans;
rep(i, maxt * ) {
if (f[i] >= l) {
ans = i;
break;
}
}
cout << ans << endl;
}
return ;
}

[zoj3623]背包模型的更多相关文章

  1. HDU 1171 背包

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  2. 【DP_背包专题】 背包九讲

    这段时间看了<背包九讲>,在HUST VJUDGE上找到了一个题单,挑选了其中16道题集中做了下,选题全部是HDU上的题,大多是简单题.目前做了点小总结,大概提了下每道题的思路重点部分,希 ...

  3. hdu2159 FATE 经典二维背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2159 思路: 定义ans存当前满足条件的消耗的最小的忍耐值(满足条件的忍耐值为在当前消耗的忍耐值的情况 ...

  4. Dividing POJ - 1014 多重背包二进制优化

    多重背包模型  写的时候漏了一个等号找了半天 i<<=1 !!!!!! #include<iostream> #include<cstdio> #include&l ...

  5. Cash Machine POJ - 1276 多重背包二进制优化

    题意:多重背包模型  n种物品 每个m个  问背包容量下最多拿多少 这里要用二进制优化不然会超时 #include<iostream> #include<cstdio> #in ...

  6. poj1015 正解--二维DP(完全背包)

    题目链接:http://poj.org/problem?id=1015 错误解法: 网上很多解法是错误的,用dp[i][j]表示选择i个人差值为j的最优解,用path[i][j]存储路径,循环次序为“ ...

  7. CH5402 选课【树形DP】【背包】

    5402 选课 0x50「动态规划」例题 描述 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了 N(N≤300) 门的选修课程,每个学生可选课程的数量 M 是 ...

  8. HDU 1171 Big Event in HDU【01背包/求两堆数分别求和以后的差最小】

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

  9. HDU - 5534 Partial Tree(每种都装的完全背包)

    Partial Tree In mathematics, and more specifically in graph theory, a tree is an undirected graph in ...

随机推荐

  1. [yii2] 实现所有action方法之前执行一段代码或者方法

    我做的是在执行任何方法之前,验证用户登陆状态! 其实就是在controller中写beforeaction()方法, 然后我的方案就是做一个基类,然后让你所有控制器继承你的基类, 如果控制器的基类用_ ...

  2. Linux学习笔记(九)Vim文本编辑器的使用

    Vim文本编辑器的使用 Vim的工作模式 1.命令模式 2.输入模式 3.编辑模式 进入Vim 1.使用Vim打开文件 2.直接进入指定位置 Vim基本命令 1.插入命令 2.光标移动命令 3.使用V ...

  3. shiro:集成Spring(四)

    基于[加密及密码比对器(三)]项目改造 引入相关依赖环境 shiro-spring已经包含 shiro-core和shiro-web 所以这两个依赖可以删掉 <!--shiro继承spring依 ...

  4. 线上Bug无法复现怎么办?老司机教你一招,SpringBoot远程调试不用愁!

    前言 在部署线上项目时,相信大家都会遇到一个问题,线上的 Bug 但是在本地不会复现,多么无奈. 此时最常用的就是取到前端传递的数据用接口测试工具测试,比如 POSTMAN,复杂不,难受不? 今天陈某 ...

  5. 破解idea2019版本至2089年(windows系统)

    1.首先必须安装idea,然后找到安装目录下的bin目录下面 2.编辑俩个以.exe.vmoptions的文件(俩个文件的最后一行都得这样写) 3.重新打开idea,找到help下面的Register ...

  6. linux下文件的打包和压缩

    文章来源:linux下文件的打包和压缩 目录 一.文件压缩的原理 二.linux常见的压缩指令 三.常用实例 1.tar命令 2.zip命令 3.gz命令 4.bz2命令 5.xz命令(必须分两步) ...

  7. [Windows]允许未签名的驱动

    bcdedit.exe -set loadoptions ENABLE_INTEGRITY_CHECKS bcdedit.exe -set TESTSIGNING OFF https://social ...

  8. Spring Boot中Spring data注解的使用

    文章目录 Spring Data Annotations @Transactional @NoRepositoryBean @Param @Id @Transient @CreatedBy, @Las ...

  9. ubuntu(物理机)连接ARM开发板

    非虚拟机 ubuntu下连接开发板 首先安装超级终端minicom sudo apt-get install minicom 安装完minicom以后,需要将开发板和电脑进行物理连接.需要使用一条网线 ...

  10. 限流 - Guava RateLimiter

    2019独角兽企业重金招聘Python工程师标准>>> 限流 限流的目的是通过对并发访问/请求进行限速或者一个时间窗口内的的请求进行限速来保护系统,一旦并发访问/请求达到限制速率或者 ...