hdu2191 题目太长不打了orz(多重背包)
来源:互联网 发布:捕鱼机网络后台服务器 编辑:程序博客网 时间:2024/04/29 10:02
第一次见这么长的题目……
多重背包,可以说背包九讲的模版题。
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;int v;int dp[105],p[105],h[105],c[105];void ZeroOnePack(int cost,int weight){ for(int i=v;i>=cost;i--) dp[i]=max(dp[i],dp[i-cost]+weight);}void CompletePack(int cost,int weight){ for(int i=cost;i<=v;i++) dp[i]=max(dp[i],dp[i-cost]+weight);}void MultipliesPack(int cost,int weight,int amount){ if(cost*amount>=v)CompletePack(cost,weight); else { for(int k=1;k<amount;) { ZeroOnePack(k*cost,k*weight); amount-=k; k<<=1; } ZeroOnePack(amount*cost,amount*weight); }}int main(){ int t,m; scanf("%d",&t); while(t--) { memset(dp,0,sizeof(dp)); scanf("%d%d",&v,&m); for(int i=1;i<=m;i++) { scanf("%d%d%d",&p[i],&h[i],&c[i]); MultipliesPack(p[i],h[i],c[i]); } printf("%d\n",dp[v]); } return 0;}
0 0
- hdu2191 题目太长不打了orz(多重背包)
- hdu2191(多重背包)
- hdu2191(多重背包)
- HDU2191(多重背包)
- 多重背包(HDU2191)
- hdu2191(多重背包问题)
- HDU2191(水多重背包)
- hdu2191 多重背包(dp)
- hdu2191(多重背包)
- hdu2191多重背包
- HDU2191多重背包问题
- hdu2191(多重背包)
- HDU2191多重背包
- hdu2191 多重背包
- hdu2191 多重背包问题
- DP--多重背包--HDU2191
- HDU2191 多重背包
- HDU2191(多重背包)
- Tesseract-OCR3.0语言库训练步骤
- 增加/dev/shm空间大小
- 日报2015/11/10(第一行代码读书笔记)
- UI基础知识 -- 自定义视图
- Android M 新特性
- hdu2191 题目太长不打了orz(多重背包)
- SpringMVC 源代码深度解析(context:component-scan)(扫描和注册的注解Bean)
- 8数码 --- N数码 的数学分析
- Android 系统工具类SystemUtils收集整理(持续更新)
- [kuangbin带你飞]专题一 简单搜索 M - 非常可乐 HDU 1495
- ubuntu14下nginx + php 安装方法(验证可行)
- 题目1489:计算两个矩阵的乘积
- Unbuntu下Android studio报Unable to recreate missing debug keystore错误
- 【android】在xml文件中定义drawable数组、id数组等