[01背包]HOJ 2196 Job Scheduling by Open Bidding

传送门:Job Scheduling by Open Bidding

Job Scheduling by Open Bidding

My Tags  (Edit)
  Source : The 2005 ACM Pacific Northwest Programming Contest
  Time limit : 1 sec   Memory limit : 32 M

Submitted : 648, Accepted : 168

Your team is setting up a computing resource devoted to batch processing of compute-bound jobs. In addition, you have decided to use static scheduling for each period of time. Naturally, you wish to maximize the income for each set of jobs run, and you have been given the responsibility of finding an optimal mix of jobs for each set of candidate jobs. The jobs are submitted by an open bid process: clients will specify the amount of processor time they wish to reserve and the dollar amount that they wish to pay. If a job finishes early, the client will still pay the full amount, and if a job exceeds the requested time, it will be terminated and (of course) the client will still pay the full amount. For purposes of scheduling, your team assumes that each job will in fact use its entire scheduled time slot. In the interests of good customer relations, though, you are not to include a bid in the schedule if there is not sufficient time available to satisfy it — we’re not going to over-book like the airlines do, and then hope someone doesn’t use the full allotment!

Input

The input file begins with a line containing a single integer (no white space) specifying the number of problem sets in the file.

Each problem set consists of (n+2) lines (no white space except as specified):

  • a single integer n (n <= 500) specifying the number of candidate jobs to be schedu
  • n lines giving the bid as an integer specifying the number of seconds followed by a single space and then a dollar amount given in decimal form (always showing two digits to the right of the decimal point)
  • a single integer t (t <= 2000) specifying the amount of time to be scheduled with these job

Output

Each problem set will be numbered (beginning at one) and will generate a single line: Problem : seconds scheduled for $abc.de where is replaced by the problem set number, is replaced with the total time actually scheduled (possibly not the full input time), and $abc.de is replaced by the dollar amount, given always with the leading currency symbol and with two digits to the right of the decimal point. There will be no blank lines, and the final line will end with the new-line character.

Sample Input

1
10
19 0.78
12 0.31
17 0.77
22 0.77
8 0.56
10 0.33
17 0.35
24 0.12
22 0.70
5 0.52
120
Sample Output
Problem 1: 120 seconds scheduled for $4.78

结题报告:

此题为经典的01背包。状态转移方程:dp[j]=max(dp[j],dp[j-E[i].v]+E[i].w);

然后找出最大时间和金钱即可。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct node{
    int v;
    double w;
}E[505];
double dp[2005];
int main(){
    int t,n,times,s;
    int i,j;
    scanf("%d",&t);
    s=0;
    while(t--){
        scanf("%d",&n);
        for(i=1;i<=n;i++)
            scanf("%d%lf",&E[i].v,&E[i].w);
        scanf("%d",×);
        memset(dp,0,sizeof(dp));
        for(i=1;i<=n;i++)
            for(j=times;j>=E[i].v;j--)
                dp[j]=max(dp[j],dp[j-E[i].v]+E[i].w);
        int maxnt=0;
        double maxn=0;
        for(i=1;i<=times;i++)
            if(dp[i]>maxn){
                maxn=dp[i];
                maxnt=i;
            }
        printf("Problem %d: %d seconds scheduled for $%.2lf\n",++s,maxnt,maxn);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值