最佳调度问题(SSOJ-2367)

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 3

Sample Output

17

思路:多机并行调度模版题

Source Program

#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("%d\n",res);
    return 0;
}
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值