[zoj3623]背包模型
给定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]背包模型的更多相关文章
- HDU 1171 背包
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 【DP_背包专题】 背包九讲
这段时间看了<背包九讲>,在HUST VJUDGE上找到了一个题单,挑选了其中16道题集中做了下,选题全部是HDU上的题,大多是简单题.目前做了点小总结,大概提了下每道题的思路重点部分,希 ...
- hdu2159 FATE 经典二维背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2159 思路: 定义ans存当前满足条件的消耗的最小的忍耐值(满足条件的忍耐值为在当前消耗的忍耐值的情况 ...
- Dividing POJ - 1014 多重背包二进制优化
多重背包模型 写的时候漏了一个等号找了半天 i<<=1 !!!!!! #include<iostream> #include<cstdio> #include&l ...
- Cash Machine POJ - 1276 多重背包二进制优化
题意:多重背包模型 n种物品 每个m个 问背包容量下最多拿多少 这里要用二进制优化不然会超时 #include<iostream> #include<cstdio> #in ...
- poj1015 正解--二维DP(完全背包)
题目链接:http://poj.org/problem?id=1015 错误解法: 网上很多解法是错误的,用dp[i][j]表示选择i个人差值为j的最优解,用path[i][j]存储路径,循环次序为“ ...
- CH5402 选课【树形DP】【背包】
5402 选课 0x50「动态规划」例题 描述 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了 N(N≤300) 门的选修课程,每个学生可选课程的数量 M 是 ...
- 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 ...
- HDU - 5534 Partial Tree(每种都装的完全背包)
Partial Tree In mathematics, and more specifically in graph theory, a tree is an undirected graph in ...
随机推荐
- 教你如何入手用python实现简单爬虫微信公众号并下载视频
主要功能 如何简单爬虫微信公众号 获取信息:标题.摘要.封面.文章地址 自动批量下载公众号内的视频 一.获取公众号信息:标题.摘要.封面.文章URL 操作步骤: 1.先自己申请一个公众号 2.登录自己 ...
- PHP Curl 请求https 60错误解决办法
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
- vue2.x学习笔记(十七)
接着前面的内容:https://www.cnblogs.com/yanggb/p/12616847.html. 动态组件&异步组件 在前面学习组件基础的时候学习过动态组件,官方文档给出过一个例 ...
- Python神库分享之geoip2 IP定位库
先安装这两个 pip install python-geoip-geolite2 -i https://pypi.douban.com/simple pip install geoip2 然后下载资源 ...
- tensorflow1.0 构建卷积神经网络
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import os os.envi ...
- linux上Docker安装gogs私服亲测(详解)
一.前言 有网友问我为什么要使用私服,可能大部分人都不是太懂,网上那么多存储仓库而且好用方便,但是你想过没有如果企业中的项目,放在人家的仓库上这个安全性不是太好,所以说一般企业都会有自己的私服.本章教 ...
- CSS选择器与CSS的继承,层叠和特殊性
什么是选择器?选择器{样式;},在{}之前的部分就是"选择器","选择器"指明了{}中的"样式"的作用对象,也就是"样式" ...
- 8、Flink Table API & Flink Sql API
一.概述 上图是flink的分层模型,Table API 和 SQL 处于最顶端,是 Flink 提供的高级 API 操作.Flink SQL 是 Flink 实时计算为简化计算模型,降低用户使用实时 ...
- 在php中如何实现cookie即时生效,不用刷新就可以使用
参考:https://www.jianshu.com/p/0468ef5dbf4d 今天在用php设置cookie的时候,发现cookie如果只是赋值一次的话,要手动刷新一下浏览器才能把数据及时更新, ...
- php utf-8
header(”Content-Type: text/html; charset=UTF-8″) 控制器控释模板输出: 值: array (size=8) 1 => array (size=4) ...