hdu 2126
背包,输出方案数!
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 505
using namespace std; int f[maxn];
int cot[maxn];
int num[maxn]; int main()
{
int n,m,t;
scanf("%d",&t);
while(t--)
{
int mi=<<;
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
{
scanf("%d",&num[i]);
mi=min(mi,num[i]);
}
if(m<mi)
{
puts("Sorry, you can't buy anything.");
continue;
}
memset(f,,sizeof f);
memset(cot,,sizeof cot);
for(int i=; i<=m; i++)
cot[i]=;
for(int i=; i<=n; i++)
{
for(int j=m; j>=num[i]; j--)
{
if(f[j]==f[j-num[i]]+)
cot[j]+=cot[j-num[i]];
else if(f[j]<f[j-num[i]]+)
{
cot[j]=cot[j-num[i]];
}
f[j]=max(f[j],f[j-num[i]]+);
// printf("%d %d| ",f[j],cot[j]);
}
// puts("");
}
printf("You have %d selection(s) to buy with %d kind(s) of souvenirs.\n",cot[m],f[m]);
}
return ;
}
hdu 2126的更多相关文章
- [HDU 2126] Buy the souvenirs (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2126 题意:给你n个物品,m元钱,问你最多能买个多少物品,并且有多少种解决方案. 一开始想到的是,先解 ...
- (01背包)Buy the souvenirs (hdu 2126)
http://acm.hdu.edu.cn/showproblem.php?pid=2126 Buy the souvenirs Time Limit: 10000/1000 MS (Java/Oth ...
- HDU 2126 Buy the souvenirs (01背包,输出方案数)
题意:给出t组数据 每组数据给出n和m,n代表商品个数,m代表你所拥有的钱,然后给出n个商品的价值 问你所能买到的最大件数,和对应的方案数.思路: 如果将物品的价格看做容量,将它的件数1看做价值的话, ...
- hdu 2126 Buy the souvenirs 二维01背包方案总数
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 2126 01背包(求方案数)
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 2126 Buy the souvenirs(记录总方案数的01背包)
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 2126 (背包方法数) Buy the souvenirs
DP还有很长很长一段路要走.. 题意:给出n纪念品的价格和钱数m,问最多能买多少件纪念品和买这些数量的纪念品的方案数. 首先,求能买最多的纪念品的数量,用贪心法可以解决.将价钱排序,然后从最便宜的开始 ...
- hdu 2126 Buy the souvenirs 【输出方案数】【01背包】(经典)
题目链接:https://vjudge.net/contest/103424#problem/K 转载于:https://blog.csdn.net/acm_davidcn/article/detai ...
- hdu 2126 Buy the souvenirs 买纪念品(01背包,略变形)
题意: 给出一些纪念品的价格,先算出手上的钱最多能买多少种东西k,然后求手上的钱能买k种东西的方案数.也就是你想要买最多种东西,而最多种又有多少种组合可选择. 思路: 01背包.显然要先算出手上的钱m ...
随机推荐
- 关于Comparator和Comparable
1.Comparable 2.Comparator >>>>>> Comparable & Comparator 都是用来实现集合中元素的比较.排序的,只 ...
- 关于egit的日常操作总结
$git fetch -p --prune -p -- remove any remote tracking branches that no longer exist remotely prune的 ...
- nodejs使用express4框架默认app.js配置说明
var express = require('express'); //引入express模块 var path = require('path'); //引入path模块,该模块包括了一些处理文件路 ...
- java算法小知识练习
偶尔翻开了以前的练习题,不自觉又想随手敲一遍,虽然有些思想依然是那么老套,但毕竟也算是对知识的巩固 了. 一.题目:有1.2.3.4四个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 具体 ...
- .NET学习笔记(2) — IIS服务器环境搭建
目录 一:开启Windows系统自带的IIS服务器方法 二:备注 三:常见问题 一:开启Windows系统自带的IIS服务器方法 第一步:安装IIS,控制面板->程序和功能-> ...
- 今天学习image在html中的应用
今天学习image在html中的应用 上次在学习超级链接的使用中有一小问题,是在添加网址中href="http://www.baidu.com" 中不能忘记http://,否则链接 ...
- 【转】The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?...
[转]The content of element type "configuration" must match "(properties?,settings?,typ ...
- Dremel made simple with Parquet
http://lastorder.me/tag/parquet.html https://blog.twitter.com/2013/dremel-made-simple-with-parquet 对 ...
- 第十篇、自定义UIBarButtonItem和UIButton block回调
// 自定义导航栏左边按钮 self.navigationItem.leftBarButtonItem = [JQBlockedBarButtonItem blockedBarButtonItemWi ...
- MySQL5.7 linux二进制安装
200 ? "200px" : this.width)!important;} --> 介绍 MySQL5.7出来也有大半年了,业内也一直在宣传5.7有多么的N,官网的也是宣 ...