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的更多相关文章

  1. HDU 3732 Ahui Writes Word(多重背包)

    HDU 3732 Ahui Writes Word(多重背包) http://acm.hdu.edu.cn/showproblem.php? pid=3732 题意: 初始有N个物品, 每一个物品有c ...

  2. 3732 Ahui Writes Word

    // N个物品 放进容量为C的背包里面 要求价值最大// 一看 第一反应是0 1背包 不过 N=100000 C=10000// 注意到 v,c在 10以内// 那么 最多就100种组合了 然后就转化 ...

  3. hdu 3732 Ahui Writes Word

    这是一道背包题,当你题读完了的时候,你会觉得这道题明明就是01背包的完全版吗! no no no no no no  no no  no no no~~~~~~~~~~~~~~~~~~~~~~~~~~ ...

  4. 【HDOJ】3732 Ahui Writes Word

    初看01背包,果断TLE.是因为n和C都比较大.但是vi和ci却很小,转化为多重背包. #include <cstdio> #include <cstring> ][]; ]; ...

  5. HDU 3732 Ahui Writes Word 多重背包优化01背包

    题目大意:有n个单词,m的耐心,每个单词有一定的价值,以及学习这个单词所消耗的耐心,耐心消耗完则,无法学习.问能学到的单词的最大价值为多少. 题目思路:很明显的01背包,但如果按常规的方法解决时间复杂 ...

  6. hdoj 3732 Ahui Writes Word (多重背包)

    之前在做背包的题目时看到了这道题,一看,大喜,这不是裸裸的01背包吗!!  然后华丽丽的超时,相信很多人也和我一样没有考虑到数据量的大小. 时隔多日,回过头来看这道题,依旧毫无头绪....不过相比之前 ...

  7. HDU3732 背包DP

    Ahui Writes Word Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. 【二进制拆分多重背包】【HDU1059】【Dividing】

    Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. HDU_3732_(多重背包)

    Ahui Writes Word Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. windows下根据端口号杀死进程

    Windows不像Linux,Unix那样,ps -ef 查出端口和进程号,然后根据进程号直接kill进程. Windows根据端口号杀死进程要分三步: 第一步 根据端口号寻找进程号 C:\>n ...

  2. Swift实战-豆瓣电台(九)简单手势控制暂停播放(全文完)

    Swift实战-豆瓣电台(九)简单手势控制暂停播放 全屏清晰观看地址:http://www.tudou.com/programs/view/tANnovvxR8U/ 这节我们主要讲UITapGestu ...

  3. php 随机生成

    php随机生成6位字符串: $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';        $max = ...

  4. 侧菜单栏的实现SlidingPaneLayout

    SlidingPaneLayout分为两部分,上面的 左划出部分和没划出的时候 <?xml version="1.0" encoding="utf-8"? ...

  5. spark join broadcast优化

    在大量数据中对一些字段进行关联. 举例 ipTable:需要进行关联的几千条ip数据(70k) hist:历史数据(百亿级别) 直接join将会对所有数据进行shuffle,需要大量的io操作,相同的 ...

  6. Workflow Mailer Notifications设置

    参考:http://www.docin.com/p-651716490.html http://www.360doc.com/content/12/0218/15/3200886_187602886. ...

  7. fnd_profile.value('AFLOG_ENABLED')的取值 和配置文件相关SQL

    SELECT * FROM FND_PROFILE_OPTIONS_VL TT WHERE TT.PROFILE_OPTION_NAME LIKE '%AFLOG%' FND:启用调试日志 详细的参考 ...

  8. jQuery学习之prop和attr的区别

    1.attr() :默认保存的是浏览器的初始值  prop()保存的是更新的值 2.下面的是首用法,但是.attr()方法可以运行在所有的attributes情况下. 注意:一些DOM元素的prope ...

  9. android 学习随笔五(界面)

    把数据库内容显示到界面 清单文件设置为线性布局(5大布局属于ViewGroup) 在清单文件中可以增加View显示 LinearLayout ll = (LinearLayout) findViewB ...

  10. 160922、配置:spring通过profile或@profile配置不同的环境(测试、开发、生产)

    一.配置环境 applicationContext.xml中添加下边的内容(develop:开发环境,production:生产环境,test:测试环境) 注意:profile的定义一定要在文档的最下 ...