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. Python:使用pymssql批量插入csv文件到数据库测试

    并行进程怎么使用? import os import sys import time def processFunc(i): time.sleep(10-i) print i if __name__= ...

  2. paml正选择处理时序列里有终止密码子怎么处理掉

     先用氨基酸序列进行比对,然后追溯回核苷酸序列,根据氨基酸序列的gap进行密码子去gap,这样不会出现终止子,能最大可能的保留其生物学意义 

  3. Lintcode: Segment Tree Query II

    For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote ...

  4. TPageControl组件

    TPageControl的功能是创建多个Dialog页,而这些重叠的每一个页Dialog就是通过TTabSheet对象实现的

  5. poj: 2739

    挺简单,生成素数表之后建个全素数的vector,然后..随便玩咯 #include <iostream> #include <stdio.h> #include <str ...

  6. monkey测试(转)

    一.Monkey测试简介Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕.滑动Trackball.按键等操作来对设备上的程序进行压力测试,检测程序多久的时 ...

  7. 3D语音天气球(源码分享)——通过天气服务动态创建3D球

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 这个项目准备分四部分介绍: 一:创建可旋转的"3D球":3 ...

  8. paper 79:MATLAB函数,interp1

    在matlab中有一个interp1()函数,可以帮助解决问题,具体情况如下:MATLAB中的插值函数为interp1,其调用格式为: yi= interp1(x,y,xi,'method') 其中x ...

  9. paper 75:使用MATLAB的神经网络工具箱创建神经网络

    % 生成训练样本集 clear all; clc; P=[110 0.807 240 0.2 15 1 18 2 1.5; 110 2.865 240 0.1 15 2 12 1 2; 110 2.5 ...

  10. JSP-04- 实现数据的保存

    .1  Session 一段时间内,单个客户与Web服务器的一连串相关的交换过程. Ø  4.1.1  应用的场景: 用户登录后保存用户状态 确定用户的唯一   Sessin.getId(); Ø  ...