1#include <iostream>2#include <string.h>3#include <cmath>4 #defineM 415 #defineMin (A, b) (A<B?A:B)6 #defineMax (A, B) (A>B?A:B)7 #defineINF 1<<308 using namespacestd;9 inttime[m][4];Ten intC1, c2, COM, g, stime;//C1 C2 time to save two independent CPUs (not the time of the G-memory GPU for simultaneous COM storage ) One intN; A voidSlove (intKintC1,intC2,intComintGintsum) - { - if(k <=N) the for(inti =0; I <4; i++) - Switch(i) - { - Case 0://1*cpu +C1 < C2? Slove (k +1, C1 + time[k][i], c2, COM, g, Max (max (C1 + time[k][i], C2) +com, g)) : -Slove (k +1, C1, C2 + time[k][i], com, g, Max (Max (c1, C2 + time[k][i]) +com, g)); + Break; A Case 1://2*cpu atSlove (k +1, c1, c2, COM + time[k][i], G, Max (C1, c2) + COM +Time[k][i], g)); - Break; - Case 2: -C1 < C2? Slove (k +1, C1 + time[k][i], c2, COM, G + time[k][i], Max (max (C1 + time[k][i], C2) + com, G +Time[k][i])) : -Slove (k +1, C1, C2 + time[k][i], com, G + time[k][i], Max (Max (c1, C2 + time[k][i]) + com, G +time[k][i])); - Break; in Case 3: -Slove (k +1, c1, c2, COM + time[k][i], G + time[k][i], Max (Max (c1, c2) + COM + time[k][i], G +time[k][i])); to Break; + } - Else the if(Stime >sum) *Stime =sum; $ }Panax Notoginseng intMain () - { theStime =inf; +C1 = C2 = G = com =0;//Initialize ACIN >>N; the for(inti =1; I <= N; i++) + for(intj =0; J <4; J + +) -CIN >>Time[i][j]; $Slove (1,0,0,0,0,0); $cout << stime <<Endl; - return 0; -}
CCF-CSP task scheduling, backtracking algorithm I think ok God **wa.