1 #include<stdio.h>
2 #include<stdlib.h>
3 void Fastest_Way(int * a, int n, int * t, int * e, int * x)
4 {//定义一个二维数组a[2][n],二维数组t[2][n-1]
5 //定义一位数组e[2],x[2];
6 int f[2][n];
7 int l[2][n];
8 int F, L;
9 f[0][0] = e[0] + *(a); //开始进入装配线1
10 f[1][0] = e[1] + *(a + n); //开始进入装配线2
11 for(int j = 1; j < n; j++)
12 {
13 if((f[0][j - 1] + *(a + j)) <= (f[1][j - 1] + *(t + n - 1 + j - 1) + *(a + j)))
14 {
15 f[0][j] = f[0][j - 1] + *(a + j);
16 l[0][j] = 1;
17 }
18 else
19 {
20 f[0][j] = f[1][j - 1] + *(t + n - 1 + j - 1) + *(a + j);
21 l[0][j] = 2;
22 }
23 if((f[1][j - 1] + *(a + n + j)) <= (f[0][j - 1] + *(t + j - 1) + *(a + n + j)))
24 {
25 f[1][j] = f[1][j - 1] + *(a + n + j);
26 l[1][j] = 2;
27 }
28 else
29 {
30 f[1][j] = f[0][j - 1] + *(t + j - 1) + *(a + n + j);
31 l[1][j] = 1;
32 }
33 }
34 if((f[0][n - 1] + x[0]) <= (f[1][n - 1] + x[1]))
35 {
36 F = f[0][n - 1] + x[0];
37 L = 1;
38 }
39 else
40 {
41 F = f[1][n - 1] + x[1];
42 L = 2;
43 }
44 int i = L;
45 printf("line %d station %d\n",i, n);
46 for(int j = n - 1; j >= 1; j--)
47 {
48 i = l[i - 1][j];
49 printf("line %d station %d\n",i,j);
50 }
51
52 }
53 int main()
54 {
55 int A[2][6] = {{7,9,3,4,8,4},{8,5,6,4,5,7}};
56 int T[2][5] = {{2,3,1,3,4},{2,1,2,2,1}};
57 int E[2] = {2,4};
58 int X[2] = {3,2};
59 Fastest_Way((int *)A, 6, (int *)T, E, X);
60 system("pause");
61 return 0;
62 }