Pipeline Issues 2018 second algorithm on the machine Zexal: explanations

Subject description:

  

 

Example:

 

 

Implementing an interpreter:

The most basic assembly line scheduling problems, not even the beginning and ending values

Knowledge Point: dynamic programming, pipeline scheduling

Implementation i.e. stars can improve after the state transition equation, provided A [] [i] of the first two line stores various time spent, T [] [i] for i in the storage cost of the line switching, F [] [i] is stored in the minimum cost for each line i.

We shall have the following transfer equation for each f [] [i]:

f[0][1] = a[0][1];

f[1][1] = a[1][1];

f [0] [i] = min (f [0] [i-1] + a [0] [i] f [1] [i-1] + T [1] [i-1] + and [ 0] [i]);

f [1] [i] = min (f [1] [i-1] + and [1] [i] f [0] [i-1] + t [0] [i-1] + and [ 1] [i]);

The first two of the initial definition, the two concrete conversion.

min function takes the previous value indicates the node directly in front of a forward current of this line, the latter takes over from the previous transition node to another line and then proceeds FIG. At this time, only two lines so that only these two situations, the comparison can be obtained of the minimum cost of the line position is reached.

Multi-lines may refer to: Solution: ALS it that good? (Add a link to follow)

Compare the last n (last home) which line time to a minimum cost.

 

Pit:

Note entered more than once after the array initialization, and the state transition equation can be converted correctly

 

Complete code:

// fundamental issue pipeline scheduler 
#include <the iostream> 
the using namespace STD; 
int main () 
{ 
	iOS :: sync_with_stdio (to false); 
	int n-; 
	int FEND; 
	int I; 
	the while (n->> CIN) 
	{ 
		int A [2] [n-+. 1], T [2] [n-]; 
		// every time it takes two lines 
		for (I =. 1; I <= n-; I ++) 
			CIN >> a [0] [I]; 
		for (I =. 1; I <= n-; I ++) 
			CIN >> a [. 1] [I]; 
			
		// two different positions of the transfer line time spent 
		for (I =. 1; I <n-; I ++) 
			CIN >> T [0] [I]; 
		for (I =. 1; I <n-; I ++) 
			CIN >> T [. 1] [I]; 
		
		minimum storage time at different locations of the two lines // 
		int f [2] [n + 1 ]; 
		// initialize to prevent errors 
		F [0] [. 1] = A [0] [. 1]; 
		F [. 1] [. 1] = A [. 1] [. 1];
		 
		for (I = 2; I <= n-; i ++)
		{ 
			// state transition equation describes specific explanation see achieved 
			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]; 
			the else 
				F [0] [I] = F [. 1] [I -1] + T [. 1] [I-. 1] + A [0] [I]; 

			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]; 
			the else 
				F [. 1 ] [I] = F [0] [-I. 1] + T [0] [-I. 1] + a [. 1] [I]; 
		} 
		// two lines are respectively calculated last time it takes to obtain a minimum value 
		if ( F [0] [n-] <F [. 1] [n-]) 
			FEND = F [0] [n-]; 
		the else 
			FEND = F [. 1] [n-]; 
		COUT FEND << << '\ n-'; 
	} 
	return 0; 
}

  

 

Guess you like

Origin www.cnblogs.com/doUlikewyx/p/11700784.html