网站大量收购独家精品文档,联系QQ:2885784924

数据结构 分支界限法程序.doc

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据结构 分支界限法程序

#include stdafx.h #include iostream.h #includestdio.h #includemalloc.h #includestring.h #define MaxSize 100 //最多结点数 typedef struct aa { int weight; int Value; int ceng; struct aa *parent; //Boolean leftChild; bool leftChild; }QNode; //存放每个结点 typedef struct { QNode A[MaxSize]; int front,rear; }SqQueue; //存放结点的队列 SqQueue sq; int n; //实际物品数 int bestx[MaxSize]; // 存放最优解 int bestv; // int EnQueue(QNode *b) {if(sq.rear==MaxSize) return 0; /*sq.A[sq.rear].weight=b.weight sq.A[sq.rear].value=b.value; sq.A[sq.rear].ceng=b.ceng; sq.A[sq.rear].parent=b.parent; sq.A[sq.rear].leftchild=b.leftchild; sq.rear=sq.rear+1;*/ sq.A[sq.rear]=*b; sq.rear++; return 1; } void EnQueue1(int wt,int vt, int i ,QNode *parent, bool leftchild) { QNode *bestE=NULL,*b; if (i==n) //可行叶子结点 {if (vt==bestv) {bestE=parent; bestx[n]=(leftchild)?1:0;} /*return*/ } b= (QNode *)malloc(sizeof(QNode)); //非叶子结点 b-parent=parent; b-leftChild=leftchild; b-weight=wt; b-Value=vt; EnQueue(b);} int InitQueue(SqQueue Sq) { int i; Sq.front=0; Sq.rear=0; for(i=0;iMaxSize;i++) { Sq.A[i].weight=0; Sq.A[i].Value=0; Sq.A[i].ceng=0; Sq.A[i].parent=NULL; Sq.A[i].leftChild=false; // Sq.A[i]=NULL; } return 1; } QNode *DeQueue(SqQueue sq) {QNode *e; if(sq.front!=sq.rear) { e=sq.A[sq.front]; sq.front++; } return e; } int QueueEmpty(SqQueue sq) {if(sq.front==sq.rear) return 1; else return 0; } void main() { int wt,vt,j,c,bestv=0; //SqQueue sq; int i=1; //当前的扩展结点所在的层 int ew=0; //扩展节点所相应的当前载重量 int ev=0; //扩展结点所相应的价值 QNode *e=NULL,*bestE=NULL; QNode *t=NULL; printf(物品的个数为:); scanf(%d,n); int w[MaxSize],v[MaxSize]; printf(物品的重量 价值:\n); for(j=0;jn;j++) {scanf(%d,w[j]); scanf(%d,v[j]); printf(\n); } printf(物品的限重为:); scanf(%d,c); //Bestx=xx; InitQueue(sq); //printf(djfh); EnQue

文档评论(0)

zhuwenmeijiale + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:7065136142000003

1亿VIP精品文档

相关文档