HDU_3732_(多重背包)
Ahui Writes Word
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2915 Accepted Submission(s): 1036
Question: the maximum value Ahui can get.
Note: input words will not be the same.
Each of the next N line are a string and two integer, representing the word, the value(Vi ) and the complexity(Ci ). (0 ≤ Vi , Ci ≤ 10)
go 5 8
think 3 7
big 7 4
read 2 6
write 3 5
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; int dp[];
int cos,val,num[][];
int n,c; void zero_one(int cost,int val)
{
for(int j=c;j>=cost;j--)
dp[j]=max(dp[j],dp[j-cost]+val);
} int main()
{
while(scanf("%d%d",&n,&c)!=EOF)
{
memset(dp,,sizeof(dp));
memset(num,,sizeof(num));
for(int i=;i<n;i++)
{
char str[];
scanf("%s%d%d",str,&val,&cos);
num[val][cos]++;
}
for(int i=;i<=;i++)
for(int j=;j<=;j++)
{
if(num[i][j]>)
{
if(num[i][j]*j>c)
for(int k=j;k<=c;k++)
dp[k]=max(dp[k],dp[k-j]+i);
else
{
int tmp=,nu=num[i][j];
while(nu>tmp)
{
zero_one(j*tmp,i*tmp);
nu-=tmp;
tmp=tmp<<;
}
zero_one(j*nu,i*nu);
}
}
}
printf("%d\n",dp[c]);
}
return ;
}
HDU_3732_(多重背包)的更多相关文章
- 洛谷P1782 旅行商的背包[多重背包]
题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能 ...
- HDU 2082 找单词 (多重背包)
题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的 ...
- Poj 1276 Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26172 Accepted: 9238 Des ...
- poj 1276 Cash Machine(多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33444 Accepted: 12106 De ...
- (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)
http://poj.org/problem?id=3260 Description Farmer John has gone to town to buy some farm supplies. ...
- (多重背包+记录路径)Charlie's Change (poj 1787)
http://poj.org/problem?id=1787 描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie dri ...
- 单调队列优化DP,多重背包
单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn ...
- POJ1742 Coins[多重背包可行性]
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 34814 Accepted: 11828 Descripti ...
- POJ1276Cash Machine[多重背包可行性]
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32971 Accepted: 11950 De ...
随机推荐
- JAVA获取操作系统的信息
列出全部信息: Properties prop = System.getProperties(); prop.list(System.out); 获取某个信息: String os = prop.ge ...
- C++中使用Json的方法
使用 C++ 处理 JSON 数据交换格式 一.摘要 JSON 的全称为:JavaScript Object Notation,顾名思义,JSON 是用于标记 Javascript 对象的,JSON官 ...
- UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)
解题报告 题意: 求全部路中最大分贝最小的路. 思路: 类似floyd算法的思想.u->v能够有另外一点k.通过u->k->v来走,拿u->k和k->v的最大值和u-&g ...
- influxdb常用命令
创建数据库 create database DBName 删除数据库 drop database DBName 使用指定数据库 use DBName 显示所有表 SHOW MEASUREMENTS 删 ...
- tesnorflow conv deconv,padding
1.padding test input = tf.placeholder(tf.float32, shape=(1,2, 2,1)) simpleconv=slim.conv2d(input,1,[ ...
- iOS开发——高级篇——iOS 强制退出程序APP代码
1.先po代码 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:self.exitapplication message:@" ...
- JS的内存空间
变量对象与引用数据 概念解释 对于基本数据类型Undefined.Null.Boolean.Number.String往往保存在变量对象中 而对于引用数据类型,如Array.String.Object ...
- H264--3--NAL层的处理[6]
------------------------------H.264的NAL层处理 ------------------------------ H264以NALU(NAL unit)为单位来支持编 ...
- 【Codeforces】Round #376 (Div. 2)
http://codeforces.com/contest/731 不发题面了,自己点链接 总结一下 考场上 原以为这次要加很多raiting... 但FST狗记邓,只加了58rating 总结一下 ...
- Groonga开源搜索引擎——列存储做聚合,没有内建分布式,分片和副本是随mysql或者postgreSQL作为存储引擎由MySQL自身来做分片和副本的
1. Characteristics of Groonga ppt:http://mroonga.org/publication/presentation/groonga-mysqluc2011.pd ...