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

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

  1. #pragma comment(linker, "/STACK:10240000,10240000")
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <map>
  9. #include <queue>
  10. #include <deque>
  11. #include <cmath>
  12. #include <vector>
  13. #include <ctime>
  14. #include <cctype>
  15. #include <set>
  16.  
  17. using namespace std;
  18.  
  19. #define mem0(a) memset(a, 0, sizeof(a))
  20. #define lson l, m, rt << 1
  21. #define rson m + 1, r, rt << 1 | 1
  22. #define define_m int m = (l + r) >> 1
  23. #define rep(a, b) for (int a = 0; a < (b); a++)
  24. #define rep1(a, b) for (int a = 1; a <= (b); a++)
  25. #define all(a) (a).begin(), (a).end()
  26. #define lowbit(x) ((x) & (-(x)))
  27. #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) {}
  28. #define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
  29. #define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
  30. #define pc(a) putchar(a)
  31. #define ps(a) printf("%s", a)
  32. #define pd(a) printf("%d", a)
  33. #define sd(a) scanf("%d", &a)
  34.  
  35. typedef double db;
  36. typedef long long LL;
  37. typedef pair<int, int> pii;
  38. typedef multiset<int> msi;
  39. typedef set<int> si;
  40. typedef vector<int> vi;
  41. typedef map<int, int> mii;
  42.  
  43. const int dx[] = {, , , -, , , -, -};
  44. const int dy[] = {, , -, , -, , , -};
  45. const int maxn = 1e5 + ;
  46. const int maxm = 1e5 + ;
  47. const int maxv = 1e7 + ;
  48. const int max_val = 1e6 + ;
  49. const int MD = 1e9 +;
  50. const int INF = 1e9 + ;
  51. const double PI = acos(-1.0);
  52. const double eps = 1e-;
  53.  
  54. template<class T> T gcd(T a, T b) { return b == ? a : gcd(b, a % b); }
  55.  
  56. int f[], a[], b[];
  57.  
  58. int main() {
  59. //freopen("in.txt", "r", stdin);
  60. int n, l;
  61. while (cin >> n >> l) {
  62. rep(i, n) {
  63. sd(a[i]);
  64. sd(b[i]);
  65. }
  66. int maxt = ;
  67. mem0(f);
  68. rep(i, n) {
  69. rep(j, maxt) {
  70. f[j + a[i]] = max(f[j + a[i]], f[j] + j * b[i]);
  71. }
  72. }
  73. int ans;
  74. rep(i, maxt * ) {
  75. if (f[i] >= l) {
  76. ans = i;
  77. break;
  78. }
  79. }
  80. cout << ans << endl;
  81. }
  82. return ;
  83. }

[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. 如果这篇文章说不清epoll的本质,那就过来掐死我吧!

    转载自:https://www.toutiao.com/i6683264188661367309/ 目录 一.从网卡接收数据说起 二.如何知道接收了数据? 三.进程阻塞为什么不占用cpu资源? 四.内 ...

  2. win10下cuda安装以及利用anaconda安装pytorch-gpu过程

    安装环境:win10+2070super 1.Cuda的下载安装及配置 (1)测试本机独立显卡是否支持CUDA的安装,点击此处查询显卡是否在列表中. (2)查看自己是否能右键找到NVIDA控制面板,如 ...

  3. 永恒之蓝MS17010复现

    MS17010复现 靶机win7:192.168.41.150 攻击kali:   192.168.41.147 扫描 通过auxiliary/scanner/smb/smb_ms17_010模块扫描 ...

  4. sql查询慢 查找

    SELECT creation_time N'语句编译时间' ,last_execution_time N'上次执行时间' ,total_physical_reads N'物理读取总次数' ,tota ...

  5. PHP反序列化漏洞总结(二)

    写在前边 之前介绍了什么是序列化和反序列化,顺便演示了一个简单的反序列化漏洞,现在结合实战,开始填坑 前篇:https://www.cnblogs.com/Lee-404/p/12771032.htm ...

  6. python模块一键安装

    利用bat文件 在不懂电脑的小白电脑上一键安装你python环境所需要的模块(你想让她一个个安装,你会疯的) 先新建一个txt文件,把你需要安装的模块和版本号写进去: 然后再新建一个txt文件 然后把 ...

  7. python-trade

    https://tool.lu/pyc/在线反编译pyc import base64 correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt' flag = base64.b6 ...

  8. zabbix管理,添加监控主机

    一:添加本机为监控主机  二.监控其他Linux主机agent端 1.环境部署 [root@localhost ~]# hostname agent.zabbix.com[root@localhost ...

  9. 使用3种协议搭建yum仓库

    制作本地yum仓库 开启服务一般要关闭防火墙,selinux之后再reboot ## 方案一:FTP协议------ftp://IP 下载vsftpd---启动vsftpd---ftp://10.0. ...

  10. chrome清除缓存、不使用缓存而刷新快捷键

    Ctrl+Shift+Del  清除Google浏览器缓存的快捷键 Ctrl+Shift+R  重新加载当前网页而不使用缓存内容 转载于:https://www.cnblogs.com/JAVA-ST ...