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) ...
随机推荐
- Codeforce Round #225 Div2
这回的C- -,弄逆序,我以为要弄个正的和反的,没想到是等价的,弄两个还是正确的,结果我又没注意1和0只能指1个方向,结果弄了4个,取了4个的最小值就错了,自己作死没弄出来...,后面又玩去了...哎 ...
- ACM/ICPC竞赛
ACM知识点分类 第一类:基础算法 (1) 基础算法:枚举,贪心,递归,分治,递推,构造,模拟 (2) 动态规划:背包问题,树形dp,状态压缩dp,单调性优化,插头dp (3) 搜索:dfs,bf ...
- mysql之触发器before和after的区别
我们先做个测试: 接上篇日志建的商品表g和订单表o和触发器 假设:假设商品表有商品1,数量是10: 我们往订单表插入一条记录: insert into o(gid,much) values(1,20) ...
- 封装pdo单例模式类
<?php /** * MyPDO * @author Jason.Wei <jasonwei06@hotmail.com> * @license http://www.sunblo ...
- bzoj1758 [Wc2010]重建计划 & bzoj2599 [IOI2011]Race
两题都是树分治. 1758这题可以二分答案avgvalue,因为avgvalue=Σv(e)/s,因此二分后只需要判断Σv(e)-s*avgvalue是否大于等于0,若大于等于0则调整二分下界,否则调 ...
- SQL Server2008 错误源:.net SqlClient data provider的解决方法
今天下午直接在SQL Server 2008的Microsoft SQL Server Management Studio 中修改一张表中某个字段, 不管是删除字符还是添加都提示下面的错误. 网上很多 ...
- 04---Net基础加强
字符串常用方法: 属性: Length获取字符串中字符的个数 IsNullOrEmpty() 静态方法,判断为null或者为“” ToCharArray() 将string转换为char[] To ...
- MVC4中下拉菜单和单选框的简单设计方法
举例一: @Html.LabelFor(model => model.Gender) @Html.DropDownListFor(model => model.Gender, new[] ...
- logstash5.x改变
5.x版本 logstash中 elasticsearch插件的workers,无法配置大于1,会提示 This plugin uses the shared and doesn't need thi ...
- [CentOS] 打造vim环境
安装vim yum install vim-enhanced 安装git rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-r ...