首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

回溯法-最佳调度有关问题

2013-06-25 
回溯法--最佳调度问题#includefstream#includeiostream#include stringusing namespace stdifstrea

回溯法--最佳调度问题

#include<fstream>
#include<iostream>
#include <string>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int n,k,best;
int len[99];
int t[99];

int comp()
{
int tmp=0;
for(int i=0;i<k;i++)if(len[i]>tmp)tmp=len[i];
return tmp;
}

void search(int dep,int *len,int *t)
{
if(dep==n){
int tmp=comp();
if(tmp<best)best=tmp;
return;
}
for(int i=0;i<k;i++){
len[i]+=t[dep];
if(len[i]<best) search(dep+1,len,t);
len[i]-=t[dep];
}
}



int main()
{
int i;
fin>>n;
fin>>k;
for (int i=0;i<n;i++)
fin>>t[i];
for (i=0;i<k;i++)
len[i]=0;
search(0,len,t);
fout<<best<<endl;
return 0;
}




输出出来的output一直是0,哪里出错了?大神帮忙看看啊 搜索
[解决办法]
best赋初值 99999999

热点排行