Dynamic Programming: assembly line scheduling problem (algorithm guide ...

Source: Internet
Author: User
assembly line Scheduling problem
Problem Description:
Colonel Motor Company produces cars in factories with two assembly lines, and a car site enters every assembly line from the start,
Install the parts in some assembly stations, assuming that each line has n assembly stations and is numbered,..., N. Start entering two lines to consume
E1, E2 time, respectively, represents the time to enter two assembly lines, each assembly station needs to consume a certain amount of time, and in each
Jump between assembly stations takes a certain amount of time timei[j], your task is to calculate the shortest time to complete the assembly. (Because each line
The same numbered assembly stations are assembled with the same parts, but the time varies depending on the technology.)

Input:
N: Number of assembly stations, E1,e2: The time to enter the assembly line, X1,X2: The time of the assembly line,
The time of the N assembly station of the first line, the time of the second line n the Assembly station, the time of the n-1 of the two lines
Output:
The shortest time to complete all assembly.

Sample input:
6
2 4 3 2
7 9 3 4 8 4
8 5 6 4 5 7
2 3 1) 3 4
2 1 2) 2 1

Sample output:
38

Problem Solving Ideas:
1. The classic problem has a new harvest every time it is analyzed.
2. Now we assume the state is: Dp[i][j]: Indicates the minimum time for the J Assembly station on line I.
3. Dynamic equation: dp[i][j] = min (dp[i][j-1] + a[i][j], dp[i^1][j]+time[i^1][j-1]+a[i][j]);
(i^1 means take another line)

Code:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace Std;
#define MAX 100

int n;
int F1[max], F2[max];
int A1[max], A2[max];
int L1[max], L2[max];
int e1, e2, X1, X2;
int Time1[max], Time2[max];

int DP ()
{
int result;
F1[1] = e1 + a1[1];
F2[1] = e2 + a2[1];
for (int i = 2; I <= n; ++i)
{
if (F1[i-1] + a1[i] <= f2[i-1] + time2[i-1] + a1[i])
{
F1[i] = F1[i-1]+a1[i];
L1[i] = 1;
}
Else
{
F1[i] = F2[i-1]+time2[i-1]+a1[i];
L1[i] = 2;
}

if (F2[i-1] + a2[i] <= f1[i-1] + time1[i-1] + a2[i])
{
F2[i] = F2[i-1]+a2[i];
L2[i] = 1;
}
Else
{
F2[i] = F1[i-1]+time1[i-1]+a2[i];
L2[i] = 2;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.