算法导论15.1节 装配线调度问题
2013-03-13 20:22
232 查看
View Code
#include <stdio.h> int l[2][6] = {0}; int f[2][6] = {0}; int f1, l1; int fastWay(int a[][6], int t[][5], int *e, int *x, int n) { f[0][0] = e[0] + a[0][0]; f[1][0] = e[1] + a[1][0]; int j; for (j = 1; j < n; j++) { if (f[0][j-1] + a[0][j] <= f[1][j-1] + t[1][j-1] + a[0][j]) { f[0][j] = f[0][j-1] + a[0][j]; l[0][j] = 1; } else { f[0][j] = f[1][j-1] + t[1][j-1] + a[0][j]; l[0][j] = 2; } if (f[1][j-1] + a[1][j] <= f[0][j-1] + t[0][j-1] + a[1][j]) { f[1][j] = f[1][j-1] + a[1][j]; l[1][j] = 2; } else { f[1][j] = f[0][j-1] + t[0][j-1] + a[1][j]; l[1][j] = 1; } } if (f[0][n-1] + x[0] <= f[1][n-1] + x[1]) { f1 = f[0][n-1] + x[0]; l1 = 1; } else { f1 = f[1][n-1] + x[1]; l1 = 2; } } void printStation(int l[][6], int l1, int n) { int i, j; i = l1; printf("line %d, station %d\n", i, n); for (j = n; j > 1; j--) { i = l[i-1][j-1]; printf("line %d, station %d\n", i, j-1); } } int main() { int e[2] = {2, 4}; int x[2] = {3, 2}; int a[2][6] = {7, 9, 3, 4, 8, 4, 8, 5, 6, 4, 5, 7}; int t[2][5] = {2, 3, 1, 3, 4, 2, 1, 2, 2, 1}; fastWay(a, t, e, x, 6); printStation(l, l1, 6); return 0; }
相关文章推荐
- [置顶] 算法导论 之 动态规划 - 装配线调度问题[C语言]
- [动态规划] 《算法导论》中的装配线调度问题实现
- 算法导论 第15章 动态规划 装配线调度问题
- 算法导论 动态规划入门之装配线调度问题
- 算法导论-装配线调度问题
- 动态规划之装配线调度问题
- 流水线调度最优问题(装配线调度问题)动态规划 O(n)时间(线性时间)C++实现
- 算法导论15.1 装配线调度问题
- 动态规划--装配线调度问题
- [算法导论读书笔记]装配线调度问题
- 《算法导论》第15章 动态规划 (1)装配线调度
- 《算法导论》第15章 动态规划 (1)装配线调度
- 算法导论-动态规划-装配线调度
- 装配线调度问题
- 动态规划之 装配线调度问题
- 动态规划(DP)-装配线调度问题
- 《算法导论》第15章 动态规划 (1)装配线调度
- 《算法导论》笔记 第15章 15.1 装配线调度
- 动态规划: 装配线调度问题 (算法导…
- 《算法导论》第15章 动态规划 (1)装配线调度