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

Problem Description
We all know that English is very important, so Ahui strive for this in order to learn more English words. To know that word has its value and complexity of writing (the length of each word does not exceed 10 by only lowercase letters), Ahui wrote the complexity of the total is less than or equal to C.
Question: the maximum value Ahui can get.
Note: input words will not be the same.
 
Input
The first line of each test case are two integer N , C, representing the number of Ahui’s words and the total complexity of written words. (1 ≤ N ≤ 100000, 1 ≤ C ≤ 10000)
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)
 
Output
Output the maximum value in a single line for each test case.
 
Sample Input
5 20
go 5 8
think 3 7
big 7 4
read 2 6
write 3 5
 
Sample Output
15
 
题意:每个单词有val (价值)、cos (复杂度),问消耗c的复杂度能够获得的最大价值。
 
最开始没注意数据规模,01背包超时,O(v*n)。
 
多重背包ac。
 
代码:
#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_(多重背包)的更多相关文章

  1. 洛谷P1782 旅行商的背包[多重背包]

    题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能 ...

  2. HDU 2082 找单词 (多重背包)

    题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的 ...

  3. Poj 1276 Cash Machine 多重背包

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26172   Accepted: 9238 Des ...

  4. poj 1276 Cash Machine(多重背包)

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33444   Accepted: 12106 De ...

  5. (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)

    http://poj.org/problem?id=3260   Description Farmer John has gone to town to buy some farm supplies. ...

  6. (多重背包+记录路径)Charlie's Change (poj 1787)

    http://poj.org/problem?id=1787   描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie dri ...

  7. 单调队列优化DP,多重背包

    单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn ...

  8. POJ1742 Coins[多重背包可行性]

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 34814   Accepted: 11828 Descripti ...

  9. POJ1276Cash Machine[多重背包可行性]

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32971   Accepted: 11950 De ...

随机推荐

  1. 【Record】ART:Android RunTime

    资料来自url=9xdxrhR45Uj3p450JQvTUO-dmzcWswNmABVgYAaFS0AXYDi8Q2JOzvu7y33GIOAI_8Lz7JmLrl0x6DoRW8e5oa" ...

  2. scu oj 4442 Party(2015年四川省acm程序设计竞赛)

    Party n frogs are invited to a tea party. Frogs are conveniently numbered by 1,2,-,n. The tea party ...

  3. MySQL-数据库创建与删除

    创建数据库 在MySQL中,数据库是用于存储和操作诸如表,数据库视图,触发器,存储过程等数据的对象的集合. 要在MySQL中创建数据库,使用CREATE DATABASE语句,如下: CREATE D ...

  4. 嵌入式开发之8127---DM8127如何利用EDMA搬移数据

    --------------qq:1327706646 ---------------------author:midu -------------------------------datetime ...

  5. LeetCode——Regular Expression Matching

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  6. TFLearn 在给定模型精度时候提前终止训练

    拿来主义:看我的代码,我是在模型acc和验证数据集val_acc都达到99.8%时候才终止训练. import numpy as np import tflearn from tflearn.laye ...

  7. 洛谷 P2822 [ NOIP 2017 ] 组合数问题 —— 数学

    题目:https://www.luogu.org/problemnew/show/P2822 阶乘太大,算不了: 但 k 只有 8 个质因子嘛,暴力60分: #include<iostream& ...

  8. Python 常用算法记录

    一.递归 汉诺塔算法:把A柱的盘子,移动到C柱上,最少需要移动几次,大盘子只能在小盘子下面 1.当盘子的个数为n时,移动的次数应等于2^n – 1 2.描述盘子从A到C: (1)如果A只有一个圆盘,可 ...

  9. 基于Flink的视频直播案例(上)

    目录 数据产生 Logstash部分 Kafka部分 Flink部分 配置/准备代码 视频核心指标监控 本案例参考自阿里云的视频直播解决方案之视频核心指标监控和视频直播解决方案之直播数字化运营. 基于 ...

  10. [App Store Connect帮助]四、添加 App 图标、App 预览和屏幕快照(6)设置 App 预览海报帧

    App 预览海报帧仅在 App 状态为可编辑时,才能被编辑. 必要职能:“帐户持有人”职能.“管理”职能.“App 管理”职能或“营销”职能.请参见职能权限. 在首页上,点按“我的 App”,选择您的 ...