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> # ...
随机推荐
- 字符函数库 - cctype 和 climits 中的符号常量
一. C++从C语言中继承一个与字符相关的.非常方便的函数软件包,他可以简化诸如确定字符是否为大写字母‘数字.标点符号等工作,这些函数的原型在头文件cctype(老式的为ctype.h)中定义的.例如 ...
- WindowsServer2012 R2 64位中文标准版(IIS8.5)下手动搭建PHP环境详细图文教程(二)安装IIS8.5
//来源:http://www.imaoye.com/Technology/WindowsServer2012R264IIS85.html 阿里云服务器ECS Windows Server 2012 ...
- 关于高性能javascript 笔记
最近买了本新书,准备自己吃 狗粮的同时也吃点精神食粮.笔记总结,从现在开始,看我啥时候能看完这本酥,就酱紫, begin:
- iOS Size Class使用
iOS8和iPhone6发布已经过去蛮久了,广大的果粉终于迎来了大屏iPhone,再也不用纠结为大屏买三星舍苹果了-但是对于iOS开发人员来说,迎来了和Android开发开发一样的问题->各种屏 ...
- Linux Tomcat 自启动
使用chkconfig命令 修改tomcat/bin/startup.sh,在开头的地方添加如下内容 #chkconfig: #description:tomcat auto start #proce ...
- ios发布笔录
需要一张1024x1024的icon 发布尺寸4.7英寸 1334x7505.5英寸 2208-12424英寸 1136-6403.5英寸 960-640ipad 2048x1536 视频 ip ...
- keyboard添加down按钮
self.textView.inputAccessoryView = [self addToolbar]; - (UIToolbar *)addToolbar { UIToolbar *toolbar ...
- 提取出图像中感兴趣的部分,cvSetImageRoi,Rect
在做人脸检测的时候,需要从摄像头拍摄视频中把检测到的人脸区域提取出来,网上找了很多博客,发现多数都是在用cvSetImageRoi函数,该函数声明如下:void cvSetImageROI(IplIm ...
- Eclipse Bug: Unhandled event loop exception No more handles
我的解决方法如下: I had the same problem, turned out that TeamViewer was causing this. In your TeamViewer go ...
- 针对ie9写特殊的样式
<!--ie9样式重置--> <!--[if IE 9]> <style> select { background: none; padding-right: 0 ...