hdu2126 Buy the souvenirs(01背包变化)
来源:互联网 发布:怎么查找网络打印机 编辑:程序博客网 时间:2024/03/28 16:40
hdu2126
分析
太菜了,还是没想到==,好好反省。这微博主讲的已经很到位了,我就写一下留个记录。
http://blog.csdn.net/liuqiyao_01/article/details/8753727
题目
http://acm.hdu.edu.cn/showproblem.php?pid=2126
代码
#include <iostream>#include <cstring>#include <ctime>#include <fstream>#include <cstdlib>#include <algorithm>using namespace std;int dp[40][2];int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d %d",&n,&m); for(int i=0; i<=m; i++) { dp[i][1]=1; dp[i][0]=0; } for(int i=0; i<n; i++) { int money; scanf("%d",&money); for(int j=m; j>=money; j--) { if(dp[j][0]==dp[j-money][0]+1) { dp[j][1]=dp[j][1]+dp[j-money][1]; } else if(dp[j][0]<dp[j-money][0]+1) { dp[j][0]=dp[j-money][0]+1; dp[j][1]=dp[j-money][1]; } } } if(dp[m][0]!=0) printf("You have %d selection(s) to buy with %d kind(s) of souvenirs.\n",dp[m][1],dp[m][0]); else printf("Sorry, you can't buy anything.\n"); } return 0;}
0 0
- hdu2126 Buy the souvenirs(01背包变化)
- hdu2126 Buy the souvenirs(01背包+路径)
- HDU2126:Buy the souvenirs(类01背包)
- hdu2126 Buy the souvenirs (01)
- HDU2126:Buy the souvenirs(01)
- hdu2126 Buy the souvenirs 01背包变形 dp
- hdu2126---Buy the souvenirs(01背包方案数)
- 【01背包方案数】HDU2126-Buy the souvenirs
- HDU2126:Buy the souvenirs
- hdu2126 Buy the souvenirs
- 【HDU2126】【Buy the souvenirs】
- hdu2126——Buy the souvenirs——————【01背包记录物品最多时种数】
- HDU 2126 Buy the souvenirs (01背包)
- Buy the souvenirs(方案数+01背包)
- HDU 2126 - Buy the souvenirs(01背包)
- hdu 2126 Buy the souvenirs 01背包
- HDU 2126 Buy the souvenirs (dp 二维01背包)
- HDU 2126 Buy the souvenirs(DP:01背包)
- win10 无法访问移动硬盘 提示“参数错误”
- 三大工厂模式
- x265-1.8版本-encoder/dpb.cpp注释
- 小县城也被互联网+撞了一下腰
- 一个简单的画图的程序
- hdu2126 Buy the souvenirs(01背包变化)
- 新浪微博之微博分享
- USACO 1.4 ariprog
- x265-1.8版本-encoder/dpb.h注释
- XML与DTD - 简单示例(咋个办呢 zgbn)
- ZOJ 3609 Modular Inverse
- 【BZOJ2190】【codevs2296】仪仗队,数论练习之φ的线性筛
- iOS - Runtime
- x265-1.8版本-encoder/frameencoder.cpp注释