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. weka数据预处理

    Weka数据预处理(一) 对于数据挖掘而言,我们往往仅关注实质性的挖掘算法,如分类.聚类.关联规则等,而忽视待挖掘数据的质量,但是高质量的数据才能产生高质量的挖掘结果,否则只有"Garbag ...

  2. java io读书笔记(6) Writing Arrays of Bytes

    显而易见,一次性写出一堆数据,要比一个byte一个byte的写,快多了,因此,outputstream,给出了2个增强型的write: public void write(byte[] data) t ...

  3. [摘录]quarts:feature

    Features of Quartz Runtime Environments Quartz can run embedded within another free standing applica ...

  4. ofbiz进击 第二节。 control 理解与创建

    首先要说的是,学习ofbiz,要去http://ofbiz.apache.org/官网里面,去看右边菜单里   Management Apps  的例子,然后找到类似的页面,去看调用的源码方法. co ...

  5. JSP和servlet有什么区别?

    JSP和servlet有什么区别? JSP是Servlet技术的扩展,本质上是Servlet的简易方式,更强调应用的外表表达. JSP编译后是"类servlet". Servlet ...

  6. jQuery Ajax 简单的实现跨域请求

    html 代码清单: <script type="text/javascript" src="http://www.youxiaju.com/js/jquery-1 ...

  7. 封装自己的smartyBC类

    <?php/** * Project:     Smarty: the PHP compiling template engine * File:        SmartyBC.class.p ...

  8. 1020: 部分A+B

    1020: 部分A+B 时间限制: 1 Sec  内存限制: 128 MB提交: 307  解决: 223[提交][状态][讨论版] 题目描述 正整数A的“DA(为1位整数)部分”定义为由A中所有DA ...

  9. kafka管理器kafka-manager部署安装

    运行的环境要求 Kafka 0.8.1.1+ sbt 0.13.x Java 7+ 功能 为了简化开发者和服务工程师维护Kafka集群的工作,yahoo构建了一个叫做Kafka管理器的基于Web工具, ...

  10. paper 35 :交叉验证(CrossValidation)方法思想

    交叉验证(CrossValidation)方法思想简介 以下简称交叉验证(Cross Validation)为CV.CV是用来验证分类器的性能一种统计分析方法,基本思想是把在某种意义下将原始数据(da ...