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\)虽然以前考的次 ...
随机推荐
- POJ 1947 Rebuilding Roads 树形DP
Rebuilding Roads Description The cows have reconstructed Farmer John's farm, with its N barns (1 & ...
- How to AC it
旋转卡壳 DP,网络流
- 第二篇:JMeter实现接口/性能自动化(JMeter/Ant/Jenkins)
主要是对HTML报告的优化 如果按JMeter默认设置,生成报告如下:
- mongodb学习05 操作详解(3)
高级查询选项 //简单查询 var cursor = db.foo.find({"foo" : "bar"}) //封装查询 var cursor = db.f ...
- linux 查看机器的cpu,操作系统等命令
看cpu信息,型号,几核 [root@f3 ~]# cat /proc/cpuinfo | grep name | cut -f2 -d:| uniq -c 16 Intel(R) Xeon(R) C ...
- 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest F. Friends
F. Friends time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- ccc 使用let
//如果不是恩雅,也不在移动过程中,那么移动 if (!self.hasMoved && !isHold) { var touchLoc = touch.getLocation(); ...
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
- 【POJ】2151 Check the difficulty of problems
http://poj.org/problem?id=2151 题意:T个队伍M条题目,给出每个队伍i的每题能ac的概率p[i][j],求所有队伍至少A掉1题且冠军至少A掉N题的概率(T<=100 ...
- 【BZOJ1003】1003: [ZJOI2006]物流运输trans SPFA+DP
Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格 ...