欢迎来到天天文库
浏览记录
ID:44876352
大小:73.00 KB
页数:3页
时间:2019-11-01
《动态规划实现货郎担问题》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#includeusingnamespacestd;typedeflistLISTINT;LISTINTlistAnother;LISTINTlist_result;intd[4][4]={{-1,10,15,20},{5,-1,9,10},{6,13,-1,12,},{8,8,9,-1}};//路径权值intmatrix_length=4;intgetPath(intn,LISTINTlist_org){LISTINT::iteratori;intminValue;if(n==1){i=list_org.begin();m
2、inValue=d[*i-1][0];if(list_org.size()==matrix_length-1){list_result=list_org;}}else{inttemp;i=list_org.begin();temp=*i;list_org.erase(i);i=list_org.begin();minValue=d[temp-1][*(i)-1]+getPath(n-1,list_org);if(list_org.size()==matrix_length-1){list_result=list_org;}for(intj=2;j3、.begin();for(intk=1;k4、n(intargc,char*argv[]){LISTINTlist_org;LISTINT::iteratorh;list_org.push_front(4);list_org.push_front(3);list_org.push_front(2);list_org.push_front(1);cout<<"--------货郎担问题动态规划算法--------"<5、x_length;k++){cout<<""<:";for(h=list_result.begin();h!=list_result.end();++h)cout<<*h<<"";cout<>i;return0;}
3、.begin();for(intk=1;k4、n(intargc,char*argv[]){LISTINTlist_org;LISTINT::iteratorh;list_org.push_front(4);list_org.push_front(3);list_org.push_front(2);list_org.push_front(1);cout<<"--------货郎担问题动态规划算法--------"<5、x_length;k++){cout<<""<:";for(h=list_result.begin();h!=list_result.end();++h)cout<<*h<<"";cout<>i;return0;}
4、n(intargc,char*argv[]){LISTINTlist_org;LISTINT::iteratorh;list_org.push_front(4);list_org.push_front(3);list_org.push_front(2);list_org.push_front(1);cout<<"--------货郎担问题动态规划算法--------"<5、x_length;k++){cout<<""<:";for(h=list_result.begin();h!=list_result.end();++h)cout<<*h<<"";cout<>i;return0;}
5、x_length;k++){cout<<""<:";for(h=list_result.begin();h!=list_result.end();++h)cout<<*h<<"";cout<>i;return0;}
此文档下载收益归作者所有