0-1背包问题! 用 动态规划法 做! 小弟跪求!急!

来源:百度知道 编辑:UC知道 时间:2024/06/21 08:53:02
各位大哥 帮忙用 动态规划法 做下 0-1 背包问题
我需要程序啊! 急用啊! 越快越好! 好用的我会再给加分的!急!
一楼的程序有2个错误啊
我要没错误的能运行的啊!!!! 谁来帮帮我!!!!!

2楼的程序我运行了一下第二行有一个错误啊 2楼的大哥快来再看看啊 55555

下面是我自己写的代码,用动态规划的方法解0/1背包问题。用VC6编译运行正确。供参考。
//这是头文件 knapsack.hpp
#ifndef KNAPSACK_HPP
#define KNAPSACK_HPP

using namespace std;

const int MAX_COUNT_OF_WIDGETS = 16;
const int MAX_CAPACITY_OF_KNAPSACK = 15;
// int CAPACITY_OF_KNAPSACK = 0;
// int COUNT_OF_WIDGETS = 0;
/* This struct widget is defined. */
struct Widget
{
int m_iID;
int m_iVolume;
int m_iValue;
bool m_bSelected;
};

/* This struct knapsack is defined */
struct Knapsack
{
int m_iCapacity;
int m_iValue;
};

/*
* This struct will be used in DynamicPrograming().
* m_iMaxValue indicates the maximum value can be achieved when the count of
* widgets is i and the capacity of the knapsack is j;
* m_bSelected indicates to achieve the maximum value whether the i-th widget
* is selected under the same condition stated