Ahui Writes Word
Ahui Writes Word
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2356 Accepted Submission(s): 863
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
Hint
Input data is huge,please use “scanf(“%s”,s)”
题意:每个单词都有自己的价值和复杂度,给你总的复杂度,计算最大的价值
01背包问题,但是n为100000,c为10000,所以01背包的做法必定超时,所以要转化,因为0 ≤ Vi , Ci ≤ 10,所以单词中价值与复杂度必定有大量的重复,重复的可以看成同一个,统计个数,转化为多重背包问题,二进制优化求解
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#define LL long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX = 11000;
int a[15][15];
char str[15];
int n,c;
int Dp[MAX];
int main()
{
int v,ci;
while(~scanf("%d %d",&n,&c))
{
memset(a,0,sizeof(a));
for(int i=0; i<n; i++)
{
scanf("%s %d %d",str,&v,&ci);
a[v][ci]++;
}
memset(Dp,0,sizeof(Dp));
for(int i=0; i<=10; i++)
{
for(int j=0; j<=10; j++)
{
if(a[i][j])
{
int bite=1;
int num=a[i][j];
while(num)
{
num-=bite;
for(int k=c; k>=bite*j; k--)
{
Dp[k]=max(Dp[k],Dp[k-bite*j]+bite*i);
}
if(bite*2<=num)
{
bite*=2;
}
else
{
bite=num;
}
}
}
}
}
printf("%d\n",Dp[c]);
}
return 0;
}
Ahui Writes Word的更多相关文章
- HDU 3732 Ahui Writes Word(多重背包)
HDU 3732 Ahui Writes Word(多重背包) http://acm.hdu.edu.cn/showproblem.php? pid=3732 题意: 初始有N个物品, 每一个物品有c ...
- 3732 Ahui Writes Word
// N个物品 放进容量为C的背包里面 要求价值最大// 一看 第一反应是0 1背包 不过 N=100000 C=10000// 注意到 v,c在 10以内// 那么 最多就100种组合了 然后就转化 ...
- hdu 3732 Ahui Writes Word
这是一道背包题,当你题读完了的时候,你会觉得这道题明明就是01背包的完全版吗! no no no no no no no no no no no~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
- 【HDOJ】3732 Ahui Writes Word
初看01背包,果断TLE.是因为n和C都比较大.但是vi和ci却很小,转化为多重背包. #include <cstdio> #include <cstring> ][]; ]; ...
- HDU 3732 Ahui Writes Word 多重背包优化01背包
题目大意:有n个单词,m的耐心,每个单词有一定的价值,以及学习这个单词所消耗的耐心,耐心消耗完则,无法学习.问能学到的单词的最大价值为多少. 题目思路:很明显的01背包,但如果按常规的方法解决时间复杂 ...
- hdoj 3732 Ahui Writes Word (多重背包)
之前在做背包的题目时看到了这道题,一看,大喜,这不是裸裸的01背包吗!! 然后华丽丽的超时,相信很多人也和我一样没有考虑到数据量的大小. 时隔多日,回过头来看这道题,依旧毫无头绪....不过相比之前 ...
- HDU3732 背包DP
Ahui Writes Word Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 【二进制拆分多重背包】【HDU1059】【Dividing】
Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU_3732_(多重背包)
Ahui Writes Word Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- c#操作Excel时,抛出异常:“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”
我们开发环境下,使用excel导入数据到数据库中,编译的软件起初是x86 方式,起初并未发现什么问题,一切很正常: 程序该进的过程: 后来导入文件一次就要读取几百G的数据导入数据库中,使用编译的X86 ...
- mysql Field xxx doesn't have a default value STRICT_TRANS_TABLES(存储引擎启用严格模式,非法数据值被拒绝)
今天在插入一条数据时发生错误: Field serverid doesn’t have a default value. serverid是设置成了not null int类型的,但是插入的是'',就 ...
- 我写了本破书-swift语言实战晋级
本书是一本介绍Swift实战的实用图书,旨在帮有一定编程基础的童鞋能够快速上手Swift. 本书的结构是先讲解了Swift语言的精要,没有基础的童鞋可以学习,有基础的童鞋可以当做复习. 接着讲解如何用 ...
- SQL事物
事务:保障流程的完整执行就像银行取钱,先在你账上扣钱,然后存入别人的账上:但是从你账上扣完钱了,突然网断了,对方没有收到钱,那么此时你的钱也没了,别人的钱也没加上,为了防止此类情况的出现,事务. be ...
- char 和 varchar2 区别
char 与 varchar2 区别 a:char长度固定而varchar2长度可变 b:char的遍历效率要比varchar2的效率稍高 c:char 浪费空间节省时间 varchar2浪费时间节省 ...
- swt byte[] 与 Image的转换
1. 从byte[]得到Image private static Image createImage(byte[] imageBytes) { Image image = null; try { By ...
- 查看在线EBS用户的相关信息
--查看在线EBS用户的相关信息 SELECT PAP.FULL_NAME, FU.USER_NAME, FAT.APPLICATION_NAME, FRT.RESPONSIBILITY_NAME, ...
- Script to set the Purchase Order Status to ‘OPEN’(将采购订单重新打开)
Business Requirement: The finance user requests the IT team to change the PO status to OPEN as they ...
- DB2 Unload 的时候遇到B37-04
B37-04的问题是每个Mainframer首先会遇到的问题,在Unload的时候最大的可能性是Extend次数到16次了,这时候只要加大primary或secondary就可以了,我最常用的是pri ...
- iBatis面试题
1) Ibatis中使用like ‘%#filedName#%’ 时,有什么问题? 在xml映射文件中,如果直接按如上写法,会报异常:java.sql.SQLException: Invalid ar ...