0-1背包问题
来源:互联网 发布:vc和c语言的区别 编辑:程序博客网 时间:2024/06/06 19:19
背包问题,代码有误,仅供本人参考
#include "stdafx.h"
#include<iostream>using namespace std;
int max(int a,int b)
{
return a>b?a:b;
}
int KnapSnack(int capacity,int n,int weight[],int value[])
{
int i;
int totalvalue[100]={0};
for(i=0;i<n;i++)
{
while(capacity>=0)
{
totalvalue[capacity]=max(totalvalue[capacity],totalvalue[capacity-weight[i]]+value[i]);
capacity= capacity-weight[i];
}
}
return totalvalue[capacity];
}
int _tmain(int argc, _TCHAR* argv[])
{
int weight[10]={4,5,6,3,2,7,8,9,10,11};
int value[10]={5,6,2,3,1,4,8,7,5,6};
int totalvalue=KnapSnack(30,10,weight,value);
cout<<totalvalue<<endl;
return 0;
}
0 0
- 背包问题(0-1背包、完全背包、多重背包)详解
- 背包问题和0-1背包问题
- 背包问题和0-1背包问题
- 背包问题系列--"0-1背包问题"
- 背包笔记-含0/1背包问题、完全背包问题、多重背包问题、二维背包问题、分组背包问题
- 【背包问题】背包问题之0-1背包、完全背包、多重背包
- 0-1背包问题
- 0/1背包问题
- 0,1背包问题
- 0-1背包问题
- 0/1背包问题
- 0-1背包问题
- // 0-1背包问题
- 0/1背包问题
- 0-1背包问题
- 0-1背包问题
- 0-1背包问题
- 0/1背包问题
- Vector作为返回值时出现的问题
- 利用格点证明恒等式
- .css("display","none");
- java 多线程简述
- [高考试卷]2012年四川卷
- 0-1背包问题
- 小波变换和motion信号处理(二)【转载】
- 给程序员介绍一些C++开源库
- QTableView中VerticalHeader嵌入checkbox
- MyEclipse 底色配置
- vbs 解码 unicode
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- 就任运营部部门经理就职演讲
- Django:传参问题