HDU3732 背包DP
Ahui Writes Word
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2853 Accepted Submission(s): 1018
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.
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)
Input data is huge,please use “scanf(“%s”,s)”
//很明显是01背包问题,但本题数据太大普通的01背包会超时,由于v和c都不大于10,最多有11*11组数据,统计每组数据有多少个,所以本题可以看做是多重背包
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int f[];
int N,C;
void zeroonepack(int v,int m,int ttl)
{
for(int i=ttl;i>=v;i--)
f[i]=max(f[i],f[i-v]+m);
}
void complitpack(int v,int m,int ttl)
{
for(int i=v;i<=ttl;i++)
f[i]=max(f[i],f[i-v]+m);
}
void multipack(int v,int m,int c,int ttl)
{
if(c*v>=ttl)
complitpack(v,m,ttl);
else
{
int k=;
while(k<c)
{
zeroonepack(k*v,k*m,ttl);
c-=k;
k*=;
}
zeroonepack(c*v,c*m,ttl);
}
}
int main()
{
char s[];
int val,cont;
int eg[][];
while(scanf("%d%d",&N,&C)!=EOF){
memset(f,,sizeof(f));
memset(eg,,sizeof(eg));
for(int i=;i<=N;i++)
{
scanf("%s%d%d",s,&val,&cont);
eg[val][cont]++;
}
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(eg[i][j]==) continue;
multipack(j,i,eg[i][j],C);
}
}
printf("%d\n",f[C]);
}
return ;
}
HDU3732 背包DP的更多相关文章
- 背包dp整理
01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...
- hdu 5534 Partial Tree 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- HDU 5501 The Highest Mark 背包dp
The Highest Mark Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp
B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...
- noj [1479] How many (01背包||DP||DFS)
http://ac.nbutoj.com/Problem/view.xhtml?id=1479 [1479] How many 时间限制: 1000 ms 内存限制: 65535 K 问题描述 The ...
- HDU 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- BZOJ 1004: [HNOI2008]Cards( 置换群 + burnside引理 + 背包dp + 乘法逆元 )
题意保证了是一个置换群. 根据burnside引理, 答案为Σc(f) / (M+1). c(f)表示置换f的不动点数, 而题目限制了颜色的数量, 所以还得满足题目, 用背包dp来计算.dp(x,i, ...
- G - Surf Gym - 100819S -逆向背包DP
G - Surf Gym - 100819S 思路 :有点类似 逆向背包DP , 因为这些事件发生后是对后面的时间有影响. 所以,我们 进行逆向DP,具体 见代码实现. #include<bit ...
- 树形DP和状压DP和背包DP
树形DP和状压DP和背包DP 树形\(DP\)和状压\(DP\)虽然在\(NOIp\)中考的不多,但是仍然是一个比较常用的算法,因此学好这两个\(DP\)也是很重要的.而背包\(DP\)虽然以前考的次 ...
随机推荐
- WPF RoadMap
最近ms 更新对WPF支持,http://blogs.msdn.com/b/dotnet/archive/2014/11/12/the-roadmap-for-wpf.aspx Work on imp ...
- 关于SQLSERVER联合查询一点看法
首先看一段代码 这个数据库表我就不发了,这段代码的意思是:查询Book表中大于该类图书价格平均值的图书信息, 先看()里的内容,我一个表起了两个别名,让这个表的相同的id相等,查出平均分,然后再看() ...
- 【项目经验】navicat工具 SQLServer数据库迁移MySQL
新近领了一个任务,就是把SQL Server的数据库迁移到My Sql上,经过查资料,圆满完成任务.分享一下流程. 1.首先,在自己的My Sql数据库上新建一个数据库. 2.打开新建的My Sql数 ...
- LoadRunner Pacing设置(转)
转载的,备读 在 LoadRunner 的运行场景中,有一个不大起眼的设置,可能经常会被很多人忽略,它就是Pacing .具体设置方式为: Run-Time settings à General à ...
- RTTI (Run-Time Type Identification,通过运行时类型识别) 转
参考一: RTTI(Run-Time Type Identification,通过运行时类型识别)程序能够使用基类的指针或引用来检查这些指针或引用所指的对象的实际派生类型. RTTI提供了以下两个 ...
- hdu 4000Fruit Ninja 树状数组
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- 创建com服务器
Delphi Com深入编程 第二章:
- 【Highcharts】 动态删除series
先绘制,后删除多余 var chart = new Highcharts.Chart(options); if (chart.series.length > result.dataList0.l ...
- iOS开发实用干货——强化你的Xcode控制台
f(x) 郑秀晶程序员不要整天看代码,偶尔也要看看风景?? www.90168.org先上一张我的Xcode控制台的图片让你们感受一下 酷炫控制台 是不是觉得很酷?不过仅仅是酷还是远远不够的,当你点击 ...
- 后缀数组 POJ 1743 Musical Theme
题目链接 题意:给定n个数字,求超过5个数字的,最长的,变化相同的,不相交的重复子串 分析:男人8题中的一题!数列相邻两项做差,形成新数列,即求数列中的最长重复子串(不可相交). 后缀数组+二分答案. ...