-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssembly line.java
More file actions
37 lines (29 loc) · 1.07 KB
/
Copy pathAssembly line.java
File metadata and controls
37 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class AssemblyLine {
/**
* Author:Gaurav Shrivastava
*/
public static int carAssembly(int a[][], int t[][], int e[], int x[], int NUM_STATION)
{
int T1[] = new int [NUM_STATION];
int T2[] = new int [NUM_STATION];
T1[0] = e[0] + a[0][0]; // time taken to leave first station in line 1
T2[0] = e[1] + a[1][0]; // time taken to leave first station in line 2
// Fill tables T1[] and T2[] using the above given recursive relations
for (int i = 1; i < NUM_STATION; ++i)
{
T1[i] = Math.min(T1[i-1] + a[0][i], T2[i-1] + t[1][i] + a[0][i]);
T2[i] = Math.min(T2[i-1] + a[1][i], T1[i-1] + t[0][i] + a[1][i]);
}
// Consider exit times and retutn minimum
return Math.min(T1[NUM_STATION-1] + x[0], T2[NUM_STATION-1] + x[1]);
}
//Drive Program
public static void main(String[] args) {
int a[][] = {{4, 5, 3, 2},
{2, 10, 1, 4}};
int t[][] = {{0, 7, 4, 5},
{0, 9, 2, 8}};
int e[] = {10, 12}, x[] = {18, 7};
System.out.println( carAssembly(a, t, e, x , a[0].length));
}
}