Участник:Taranov srg/Minimum Difficulty of a Job Schedule

Материал из DISCOPAL
< Участник:Taranov srg
Версия от 15:00, 9 декабря 2020; Taranov srg (обсуждение | вклад) (Новая страница: «https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule/ C <code-c> int minDifficulty(int* jobDifficulty, int jobDifficultySize, int d){ if (jobDiffi…»)

(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule/

C

int minDifficulty(int* jobDifficulty, int jobDifficultySize, int d){
	if (jobDifficultySize < d)
		return -1;
 
	int *dif_arr = (int *)malloc(sizeof(int)*jobDifficultySize*d);
	for(int i=0;i<jobDifficultySize;i++){
		dif_arr[i] = jobDifficulty[jobDifficultySize-1-i];
	};
 
	for(int i=1;i<jobDifficultySize;i++){
		dif_arr[i] = fmax(dif_arr[i], dif_arr[i-1]);
	};
 
 
	int temp_max, temp_min;
	for(int j=1; j<d; ++j){
		for(int i=j; i<jobDifficultySize; ++i){
			temp_max = jobDifficulty[jobDifficultySize-1-i];
			temp_min = dif_arr[(j-1)*jobDifficultySize + i-1] + temp_max;
			for(int k=i-1; k>=j; --k){
				temp_max = fmax(temp_max, jobDifficulty[jobDifficultySize-1-k]);
				temp_min = fmin(temp_min, temp_max + dif_arr[((j-1)*jobDifficultySize + k-1)]);
			};
			dif_arr[j*jobDifficultySize+i] = temp_min;
		};
	};
 
	return dif_arr[jobDifficultySize*d-1];
}