[동적 기획] 조립선 스케줄링 코드
#include <stdio.h>
int f[2][101];
int l[2][101];
int ff;
int ll;
void fastest_way(int n, int a[2][n], int t[2][n-1], int e[2], int x[2])
{
f[0][0] = a[0][0] + e[0];
f[1][0] = a[1][0] + e[1];
for(int j=1; j<n; j++)
{
if(f[1][j-1]+t[1][j-1]+a[0][j]<f[0][j-1]+a[0][j])
{
f[0][j] = f[1][j-1]+t[1][j-1]+a[0][j];
l[0][j] = 1;
}
else
{
f[0][j] = f[0][j-1]+a[0][j];
l[0][j] = 0;
}
if(f[0][j-1]+t[0][j-1]+a[1][j]<f[1][j-1]+a[1][j])
{
f[1][j] = f[0][j-1]+t[0][j-1]+a[1][j];
l[1][j] = 0;
}
else
{
f[1][j] = f[1][j-1]+a[1][j];
l[1][j] = 1;
}
}
if(f[0][n-1]+x[0] <= f[1][n-1]+x[1])
{
ff = f[0][n-1]+x[0];
ll = 0;
}
else
{
ff = f[1][n-1]+x[1];
ll = 1;
}
}
void print_station(int n, int ll)
{
int i = ll;
printf("line %d, station %d
", i, n);
for(int j=n-1; j>=1; j--)
{
i = l[i][j];
printf("line %d, station %d
", i, j);
}
}
int main()
{
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}};
int e[2] = {2, 4};
int x[2] = {3, 2};
fastest_way(6, a, t, e, x);
printf("Total cost: %d
", ff);
print_station(6, ll);
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.