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. 码农小汪-spring框架学习之2-spring IoC and Beans 控制反转 依赖注入 ApplicationContext BeanFactory

    spring Ioc依赖注入控制反转 事实上这个东西很好理解的,并非那么的复杂. 当某个Java对象,须要调用还有一个Java对象的时候(被依赖的对象)的方法时.曾经我们的做法是怎么做呢?主动的去创建 ...

  2. Python 批量修改root密码

    #_*_coding:utf8_*_ from multiprocessing import Process, Pool import paramiko import sys,os host_list ...

  3. ios打地鼠游戏源代码

    打地鼠游戏源代码,游戏是一款多关卡基于cocos2d的iPad打地鼠游戏源代码,这也是一款高质量的打地鼠游戏源代码,能够拥有逐步上升的关卡的设置,大家能够在关卡时设置一些商业化的模式来盈利的,很完美的 ...

  4. Codeforces Beta Round #96 (Div. 1) C. Logo Turtle DP

    C. Logo Turtle   A lot of people associate Logo programming language with turtle graphics. In this c ...

  5. BZOJ1202 [HNOI2005]狡猾的商人 并查集维护前缀和

    1202: [HNOI2005]狡猾的商人 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1935  Solved: 936[Submit][Stat ...

  6. 【bzoj4245】[ONTAK2015]OR-XOR

    利用前缀和选m个区间等价于选m个数 从最高位开始找,如果这一位至少有m个0,则可以为0,该位为1的后面就不可以选了. 还要注意,最后一个数如果该位为1,那么这一位必须为1,然后要从62开始枚举,而不是 ...

  7. 解决myeclipse在mac中Retina屏幕中模糊的终极详细方法

  8. Email-ext plugin

    https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin General This plugin extends Jenkins built i ...

  9. python datatime日期和时间值模块

    datetime.time():是一个时间类,这个类接受4个参数,分别代表时,分,秒,毫秒.参数的默认值是为0 #!/usr/bin/env python #coding:utf8 import da ...

  10. http报文和协议首部

    http报文和协议首部 http报文 3>报文格式 request 报文 <method> <request-URL> <version> <heade ...