算法导论-装配线调度问题
2012-02-06 15:58
369 查看
动态规划
void Fastest_Way() { //there is only one way to get to the first station in each line f[0][0]=e[0]+a[0][0]; f[1][0]=e[1]+a[1][0]; //two way to get to the i's station, we will choose the lower one. for(int i=1;i<n;++i) { if(f[0][i-1]+a[0][i]<f[1][i-1]+t[1][i-1]+a[0][i]) { f[0][i]=f[0][i-1]+a[0][i]; l[0][i]=0; } else { f[0][i]=f[1][i-1]+t[1][i-1]+a[0][i]; l[0][i]=1; } if(f[1][i-1]+a[1][i]<f[0][i-1]+t[0][i-1]+a[1][i]) { f[1][i]=f[1][i-1]+a[1][i]; l[1][i]=1; } else { f[1][i]=f[0][i-1]+t[0][i-1]+a[1][i]; l[1][i]=0; } } //when passing the last station, we should add the exit price, the lower will be the fastest if(f[0][n-1]+x[0]<f[1][n-1]+x[1]) { _f=f[0][n-1]+x[0]; _l=0; } else { _f=f[1][n-1]+x[1]; _l=1; } cout <<"The fastest time is "<<_f<<endl; //get the full path backward, using a stack is a good way stack<int> s; s.push(_l); for(int i=n-1;i>=1;--i) { s.push(l[_l][i]); _l=l[_l][i]; } cout <<"The fastest path is: "; for(int i=0;i<n;++i) { cout <<"S"<<"["<<s.top()+1<<"]"<<"["<<i+1<<"]"; if(i!=n-1) cout <<"->"; s.pop(); } cout <<endl; }
相关文章推荐
- [置顶] 算法导论 之 动态规划 - 装配线调度问题[C语言]
- [动态规划] 《算法导论》中的装配线调度问题实现
- 算法导论 第15章 动态规划 装配线调度问题
- 算法导论 动态规划入门之装配线调度问题
- 算法导论15.1节 装配线调度问题
- 动态规划-装配线调度问题
- 装配线调度问题 算法导论动态规划P194
- 装配线调度问题
- 算法导论 15.1动态规划 装配线调度
- 算法导论 第十六章:贪心算法之单任务调度问题
- 动态规划——装配线调度问题
- 《算法导论》笔记 第16章 *16.5 一个任务调度问题
- 算法导论--动态规划(装配线调度)
- 动态规划之装配线调度问题
- 动态规划--装配线调度问题
- [算法导论读书笔记]装配线调度问题
- 《算法导论》第15章 动态规划 (1)装配线调度
- 流水线调度最优问题(装配线调度问题)动态规划 O(n)时间(线性时间)C++实现
- 算法导论15.1 装配线调度问题
- 《算法导论》第15章 动态规划 (1)装配线调度