本文实例讲述了C#使用回溯法解决背包问题的方法。分享给大家供大家参考。具体如下:
背包问题描述:
给定一组物品,每种物品都有自己的重量和价格,在限定的总重量内,我们如何选择,才能使得物品的总价格最高
实现代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace BackRack
{
//要装入书包的货物节点
class BagNode
{
public int mark;//货物编号,从0开始记
public int weight;//货物重量
public int va