收藏 分享(赏)

回溯法背包问题.doc

上传人:kpmy5893 文档编号:7320844 上传时间:2019-05-14 格式:DOC 页数:4 大小:24.50KB
下载 相关 举报
回溯法背包问题.doc_第1页
第1页 / 共4页
回溯法背包问题.doc_第2页
第2页 / 共4页
回溯法背包问题.doc_第3页
第3页 / 共4页
回溯法背包问题.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、回溯法背包问题.txt 男人的承诺就像 80 岁老太太的牙齿,很少有真的。你嗜烟成性的时候,只有三种人会高兴,医生 你的仇人和卖香烟的。#include#include using namespace std;class Knapfriend int Knaspack(int *,int *,int ,int );public :int Bound(int i);void Backtrack(int i);int c;/背包数量int n;/物品数int *w;/物品重量数组int *p;/物品价值数组int cw;/当前重量int cp;/当前价值int bestp;/当前最有价值;void

2、 Knap:Backtrack(int i)if(in)bestp=cp;return ;if(cw+wibestp)Backtrack(i+1);int Knap:Bound(int i)int cleft=c-cw;int b=cp;while(i=a.d);int ID;float d;int Knapsack(int p,int w,int c,int n)int W=0;int P=0;Object * Q=new Objectn;for(int i=1;in;coutc;w=new int n+1;w0=0;coutwi;p=new int n+1;p0=0;coutpi;cout“最优值:“Knapsack(p,w,c,n)endl;

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报