[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 ...
随机推荐
- 如果这篇文章说不清epoll的本质,那就过来掐死我吧!
转载自:https://www.toutiao.com/i6683264188661367309/ 目录 一.从网卡接收数据说起 二.如何知道接收了数据? 三.进程阻塞为什么不占用cpu资源? 四.内 ...
- win10下cuda安装以及利用anaconda安装pytorch-gpu过程
安装环境:win10+2070super 1.Cuda的下载安装及配置 (1)测试本机独立显卡是否支持CUDA的安装,点击此处查询显卡是否在列表中. (2)查看自己是否能右键找到NVIDA控制面板,如 ...
- 永恒之蓝MS17010复现
MS17010复现 靶机win7:192.168.41.150 攻击kali: 192.168.41.147 扫描 通过auxiliary/scanner/smb/smb_ms17_010模块扫描 ...
- sql查询慢 查找
SELECT creation_time N'语句编译时间' ,last_execution_time N'上次执行时间' ,total_physical_reads N'物理读取总次数' ,tota ...
- PHP反序列化漏洞总结(二)
写在前边 之前介绍了什么是序列化和反序列化,顺便演示了一个简单的反序列化漏洞,现在结合实战,开始填坑 前篇:https://www.cnblogs.com/Lee-404/p/12771032.htm ...
- python模块一键安装
利用bat文件 在不懂电脑的小白电脑上一键安装你python环境所需要的模块(你想让她一个个安装,你会疯的) 先新建一个txt文件,把你需要安装的模块和版本号写进去: 然后再新建一个txt文件 然后把 ...
- python-trade
https://tool.lu/pyc/在线反编译pyc import base64 correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt' flag = base64.b6 ...
- zabbix管理,添加监控主机
一:添加本机为监控主机 二.监控其他Linux主机agent端 1.环境部署 [root@localhost ~]# hostname agent.zabbix.com[root@localhost ...
- 使用3种协议搭建yum仓库
制作本地yum仓库 开启服务一般要关闭防火墙,selinux之后再reboot ## 方案一:FTP协议------ftp://IP 下载vsftpd---启动vsftpd---ftp://10.0. ...
- chrome清除缓存、不使用缓存而刷新快捷键
Ctrl+Shift+Del 清除Google浏览器缓存的快捷键 Ctrl+Shift+R 重新加载当前网页而不使用缓存内容 转载于:https://www.cnblogs.com/JAVA-ST ...