题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1963

注意:题中有一句话说债券的价钱都是1000的倍数,我之前没看到这句话,写的完全背包,知道肯定是tle,然后用二进制优化还是tle,后来才发现忽略个条件。。。。

加上这个条件的话,这个就是个比较简单的完全背包了,具体见代码。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
const int maxn=1e5+;
const int INF=0x3f3f3f3f; int dp[maxn];
int w[],p[]; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int m,n,d;
scanf("%d%d",&m,&n);
scanf("%d",&d);
for(int i=; i<=d; i++)
{
scanf("%d%d",&w[i],&p[i]);
w[i]/=;
}
for(int k=; k<=n; k++)
{
memset(dp,,sizeof(dp));
int ans=m/;
for(int i=; i<=d; i++)
for(int j=w[i]; j<=ans; j++)
dp[j]=max(dp[j],dp[j-w[i]]+p[i]);
m+=dp[ans];
}
printf("%d\n",m);
}
return ;
}

hdu1963 完全背包(数据压缩)的更多相关文章

  1. HDU1963 && POJ2063:Investment(完全背包)

    Problem Description John never knew he had a grand-uncle, until he received the notary’s letter. He ...

  2. 【探索】利用 canvas 实现数据压缩

    前言 HTTP 支持 GZip 压缩,可节省不少传输资源.但遗憾的是,只有下载才有,上传并不支持.如果上传也能压缩,那就完美了.特别适合大量文本提交的场合,比如博客园,就是很好的例子. 虽然标准不支持 ...

  3. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

  4. HDU 3535 AreYouBusy (混合背包)

    题意:给你n组物品和自己有的价值s,每组有l个物品和有一种类型: 0:此组中最少选择一个 1:此组中最多选择一个 2:此组随便选 每种物品有两个值:是需要价值ci,可获得乐趣gi 问在满足条件的情况下 ...

  5. HDU2159 二维完全背包

    FATE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. CF2.D 并查集+背包

    D. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit p ...

  7. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  8. 洛谷P1782 旅行商的背包[多重背包]

    题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能 ...

  9. POJ1717 Dominoes[背包DP]

    Dominoes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6731   Accepted: 2234 Descript ...

随机推荐

  1. NHibernate实战详解(一)领域模型设计

    关于NHibernate的资料本身就不多,中文的就更少了,好在有一些翻译文章含金量很高,另外NHibernate与Hibernate的使用方式可谓神似,所以也有不少经验可以去参考Hibernate. ...

  2. 【剑指offer】题目36 数组中的逆序对

    数组中任取两个数字,如果前面的数字大于后面的数字称为一个逆序对 如:1,2,1,2,1 有3个逆序对 思路:知道O(N2)肯定是错的.开始想hash,试图找到O(n)的算法,想了很久,找不到.后来想到 ...

  3. 【leetcode】Validate Binary Search Tree(middle)

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  4. 【leetcode】 search Insert Position(middle)

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  5. c#指定日期格式

    string TripCode = "BT"+DateTime.Now.ToString("yyyyMMddHHmmss");//出差单号

  6. 修改VS2010生成的dll文件中的内容

    我的电脑是64为的操作系统,所以先找到下面的路径 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin 找到这个文件:ildasm.exe,如 ...

  7. Java常用工具类题库

    一.    填空题 在Java中每个Java基本类型在java.lang包中都在一个相应的包装类,把基本类型数据转换为对象,其中包装类Integer是___Number__的直接子类. 包装类Inte ...

  8. osgconv 批量转换

    @echo offfor /f "delims=" %%i in ('dir/b *.osg') do ( "osgconv.exe" "%%~ni. ...

  9. WAMP2.5 Forbidden

    Forbidden You don't have permission to access /DuoLamPHP/index.php on this server. Apache/2.4.9 (Win ...

  10. September 28th 2016 Week 40th Wednesday

    Love all, trust a few, do wrong to none. 爱所有人,信任一些人,不妨害任何人. Reading is a way for me to expand my min ...