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 ...
随机推荐
- 滑动条slider
#include"ui/CocosGUI.h" using namespace ui; Text* displayValudLabel = Text::create("轻 ...
- 使用blktrace排查iowait cpu高的问题
本文转自这里,blktrace在这种情况下的使用方法值得借鉴学习. ------------------------------------------------------------------ ...
- ASP伪静态页面(不需要通过iis+ISAPI_Rewrite)
很简单的教程,献给喜欢SEO的朋友们. 不需要通过iis+ISAPI_Rewrite做基于IIS的url rewrite 一.数据库很简单使用ACCESS,Data.mdb建立一个表Article,三 ...
- 【重叠I/O之系列三】I/O完成端口
一 串行模式和并行模式 一般一个服务应用程序采用以下两个架构模型之一: 串行模式 一个线程等待一个客户发出的请求,当请求到达的时候,线程会被换醒来处理客户的请求. 并发模式.一个线程等待一个客户 ...
- EF架构~过滤导航属性等,拼接SQL字符串
拼接T-SQL串,并使它具有通用性 好处:与服务器建立一次连接,给服务器发一条SQL命令,即可实现 代码如下: 1 /// <summary> 2 /// 构建Insert语句串 3 // ...
- (三)JAVA使用POI操作excel
1,单元格对齐方式 Demo8.java package com.wishwzp.poi; import java.io.FileOutputStream; import java.util.Date ...
- JavaScript基础-面向对象编程<1>
1.1 函数与对象 1.定义函数的方式定义类 定义类的方法: function class1(){ //类成员的定义及构造函数部分 } class1既是一个函数,也是一个类. 使用 new 操作符获 ...
- IO流05_OutputStream和Writer输出流
[输出流中的字节流和字符流] [OutPutStream和Writer] [ OutputStream和Writer中包含的方法 ] void write(int c) 将指定的字节/字符 ...
- 395. Longest Substring with At Least K Repeating Characters
395. Longest Substring with At Least K Repeating Characters 我的思路是先扫描一遍,然后判断是否都满足,否则,不满足的字符一定不出现,可以作为 ...
- PHPstrom 增加emmet插件
之前记得使用Eclipse的时候有一个插件叫 emmet 可以实现快速开发前端,简直就是前端开发秒杀神器: 输入对应的代码一个table键就搞定了一堆代码: 在emmet的官网上 看到其实是支持的PH ...