我是靠谱客的博主 兴奋溪流,这篇文章主要介绍最佳调度问题(SSOJ-2367)Problem DescriptionInputOutputSample InputSample OutputSource Program,现在分享给大家,希望可以做个参考。
Problem Description
假设有n个任务由k个可并行工作的机器完成。完成任务i需要的时间为ti。
试设计一个算法找出完成这n个任务的最佳调度,使得完成全部任务的时间最早。
Input
第一行有2个正整数n和k(1≤n≤20,1≤k≤6);
第二行的n个正整数是完成n个任务需要的时间ti(1≤ti≤100)。
Output
1行1个数:完成全部任务的最早时间。
Sample Input
7 3
2 14 4 16 6 5 3Sample Output
17
思路:多机并行调度模版题
Source Program
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<bitset> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 500+5; const int dx[] = {-1,1,0,0,-1,-1,1,1}; const int dy[] = {0,0,-1,1,-1,1,-1,1}; using namespace std; int n,k; int t[N]; int len[N]; int res=INF; int getTime() { int temp=0; for(int i=0; i<k; i++) temp=max(len[i],temp); return temp; } void dfs(int deep) { if(deep==n) { int temp=getTime(); res=min(res,temp); return; } for(int i=0; i<k; i++) { len[i]+=t[deep]; if(len[i]<res) dfs(deep+1); len[i]-=t[deep]; } } int main() { scanf("%d%d",&n,&k); for(int i=0; i<n; i++) scanf("%d",&t[i]); dfs(0); printf("%dn",res); return 0; }
最后
以上就是兴奋溪流最近收集整理的关于最佳调度问题(SSOJ-2367)Problem DescriptionInputOutputSample InputSample OutputSource Program的全部内容,更多相关最佳调度问题(SSOJ-2367)Problem内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复