首页 > 代码库 > ccf-csp 任务调度,回溯算法我觉得ok神**wa了

ccf-csp 任务调度,回溯算法我觉得ok神**wa了

 1 #include<iostream>
 2 #include<string.h>
 3 #include<cmath>
 4 #define M 41
 5 #define min(a,b) (a<b?a:b)
 6 #define max(a,b) (a>b?a:b)
 7 #define inf 1<<30
 8 using namespace std;
 9 int time[M][4];
10 int c1, c2, com, g, stime;//c1 c2存两个独立cpu的时间(不是同时进行 com存同时进行的时间 g存gpu的时间
11 int n;
12 void slove(int k, int c1, int c2, int com, int g, int sum)
13 {
14     if (k <= n)
15         for (int i = 0; i < 4; i++)
16             switch (i)
17             {
18             case 0://1*cpu
19                 c1 < c2 ? slove(k + 1, c1 + time[k][i], c2, com, g, max(max(c1 + time[k][i], c2) + com, g)) :
20                     slove(k + 1, c1, c2 + time[k][i], com, g, max(max(c1, c2 + time[k][i]) + com, g));
21                 break;
22             case 1://2*cpu
23                 slove(k + 1, c1, c2, com + time[k][i], g, max(max(c1, c2) + com + time[k][i], g));
24                 break;
25             case 2:
26                 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])) :
27                     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]));
28                 break;
29             case  3:
30                 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]));
31                 break;
32             }
33     else
34         if (stime >sum)
35             stime = sum;
36 }
37 int main()
38 {
39     stime = inf;
40     c1 = c2 = g = com = 0;//初始化
41     cin >> n;
42     for (int i = 1; i <= n; i++)
43         for (int j = 0; j < 4; j++)
44             cin >> time[i][j];
45     slove(1, 0, 0, 0, 0, 0);
46     cout << stime << endl;
47     return 0;
48 }

 

ccf-csp 任务调度,回溯算法我觉得ok神**wa了