UVA 624 CD (01背包)
//路径记录方法:若是dp[j-value[i]]+value[i]>dp[j]说明拿了这个东西,标志为1,
//for循环标志,发现是1,就打印出来,并把背包的容量减少,再在次容量中寻找标志;
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int value[],dp[],s[][]; int main()
{
int n,m;
while(cin>>m)
{
cin>>n;
for(int i=;i<=n;i++)
cin>>value[i];
memset(dp,,sizeof(dp));
memset(s,,sizeof(s));
for(int i=;i<=n;i++)
for(int j=m;j>=value[i];j--)
if(dp[j]<=dp[j-value[i]]+value[i])
{
dp[j]=dp[j-value[i]]+value[i];
s[i][j]=;
}
for(int i=n,j=m;i>=;i--)
{
if(s[i][j])
{
cout<<value[i]<<" ";
j=j-value[i];
}
}
cout<<"sum:"<<dp[m]<<endl;
}
return ;
}
UVA 624 CD (01背包)的更多相关文章
- UVA 624 - CD (01背包 + 打印物品)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 624 ---CD 01背包路径输出
DescriptionCD You have a long drive by car ahead. You have a tape recorder, but unfortunately your b ...
- uva 624 CD 01背包打印路径
// 集训最终開始了.来到水题先 #include <cstdio> #include <cstring> #include <algorithm> #includ ...
- UVA 624 CD(01背包+输出方案)
01背包,由于要输出方案,所以还要在dp的同时,保存一下路径. #include <iostream> #include <stdio.h> #include <stri ...
- UVA 624 CD(DP + 01背包)
CD You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music i ...
- uva 624 CD (01背包)
CD You have a long drive by car ahead. You have a tape recorder, but unfortunately your best musi ...
- UVA624 CD,01背包+打印路径,好题!
624 - CD 题意:一段n分钟的路程,磁带里有m首歌,每首歌有一个时间,求最多能听多少分钟的歌,并求出是拿几首歌. 思路:如果是求时常,直接用01背包即可,但设计到打印路径这里就用一个二维数组标记 ...
- CD(01背包)
You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music is o ...
- 紫书 习题 10-5 UVa 1213(01背包变形)
这里就是01背包多了一维物品个数罢了 记得不能重复所以有一层循环顺序要倒着来 边界f[0][0] = 1 #include<cstdio> #include<vector> # ...
随机推荐
- PXE+kickstart自动安装ubuntu14.04
本文参考了诸多文章,先感谢这些文章的作者. 使用pxe安装系统需要安装dhcp,tftp,http等服务(当然也可以使用其他文件共享方式比如nfs,ftp). 实验环境: 1. vmware 12 2 ...
- USACO 3.3 Shopping Offers
Shopping OffersIOI'95 In a certain shop, each kind of product has an integer price. For example, the ...
- hadoop,yarn和vcpu资源配置
Hadoop YARN同时支持内存和CPU两种资源的调度(默认只支持内存,如果想进一步调度CPU,需要自己进行一些配置),本文将介绍YARN是如何对这些资源进行调度和隔离的. 在YARN中,资源管理 ...
- ora2pg数据迁移
1.安装strawberry-perl-5.242.安装ora2pg-17.4 #perl Makefile.PL #dmake && dmake install3.安装ora2pg相 ...
- hdu 2829 Lawrence(斜率优化DP)
题目链接:hdu 2829 Lawrence 题意: 在一条直线型的铁路上,每个站点有各自的权重num[i],每一段铁路(边)的权重(题目上说是战略价值什么的好像)是能经过这条边的所有站点的乘积之和. ...
- Android数据库--Sqlcipher的使用(一)
1.下载官方支持包:https://s3.amazonaws.com/sqlcipher/3.2.0/sqlcipher-for-android-community-v3.2.0.zip Github ...
- java中equals方法和contentEquals方法区别
java中,String类里提供了两种字符串的比较方式(算上“==”应该是三种) String line1 = new String("0123456789"); String l ...
- C#模板打印功能-模板为WPS或Excel
//---WPS----- using EtApp = ET; using System.Reflection; using System.Runtime.InteropServices; using ...
- 判断字符串是否为UTF8编码
UTF-8(8-bit Unicode Transformation Format)是一种针对Unicode的可变长度字符编码.由Ken Thompson于1992年创建.现在已经标准化为RFC 36 ...
- 动态的改变标签内的src属性
<body> <ul> <li class='on'>1</li> <li>2</li> <li>3</li& ...