hdu 3433 A Task Process 二分+dp

 

A Task Process

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1332    Accepted Submission(s): 656

Problem Description
There are two kinds of tasks, namely A and B. There are N workers and the i-th worker would like to finish one task A in ai minutes, one task B in bi minutes. Now you have X task A and Y task B, you want to assign each worker some tasks and finish all the tasks as soon as possible. You should note that the workers are working simultaneously.
 

 

Input
In the first line there is an integer T(T<=50), indicates the number of test cases.

In each case, the first line contains three integers N(1<=N<=50), X,Y(1<=X,Y<=200). Then there are N lines, each line contain two integers ai, bi (1<=ai, bi <=1000).
 

 

Output
For each test case, output “Case d: “ at first line where d is the case number counted from one, then output the shortest time to finish all the tasks.
 

Sample Input

 

3
2 2 2
1 10
10 1
2 2 2
1 1
10 10

3 3 3
2 7
5 5
7 2


Sample Output

Case 1: 2
Case 2: 4
Case 3: 6
/*
hdu 3433 A Task Process 二分+dp(卒)

dp方面毕竟若,着实没有想出来状态转移方程
主要是数据特别小,可以考虑二分答案然后通过判断来解决
如果知道了能够使用的时间limi.假设dp[i][j]表示前i个人完成j个A任务时最多能完成多少
个B任务
转移方程:
dp[i][j] = (dp[i-1][j-k] + (limi-k*a[i])*b[i],dp[i][j])

hhh-2016-04-10 21:02:38
*/
#include <iostream>
#include <cstdio>
#include <cstring>
typedef long long ll;
using namespace std;
const int mod = 1e9+7;
const int maxn = 205;
int a[maxn],b[maxn];
int x,y,n;
int dp[maxn][maxn];
bool cal(int limi)
{
    //dp[i][j] 前i个人完成j个A任务的情况下,最多完成多少个B
    memset(dp,-1,sizeof(dp));
    for(int i =0; i <= x && i*a[1] <= limi; i++)
    {
        dp[1][i] = (limi-i*a[1])/b[1];
    }

    for(int i = 2; i <= n; i++)
    {
        for(int j = 0; j <= x; j++)
        {
            for(int k = 0; k*a[i] <= limi && k <= j; k++)
            {
                if(dp[i-1][j-k] >= 0)
                    dp[i][j] = max(dp[i][j],dp[i-1][j-k]+(limi-k*a[i])/b[i]);
                //如果不是同一个工人,那么工作进而同时进行
            }
        }
    }
    return dp[n][x] >= y;
}

int main()
{
    int T;
    int cas = 1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&x,&y);
        int ma = 0;
        for(int i =1 ; i <= n; i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            ma = max(ma,a[i]);
        }
        int l = 0,r = ma*x;
        int ans = 0;
        while(l <= r)
        {
            int mid = (l+r)>>1;

            if(cal(mid))
            {
                ans = mid;
                r = mid-1;
            }
            else
                l = mid + 1;
        }
        printf("Case %d: %d\n",cas++,ans);
    }
    return 0;
}

  



 

转载于:https://www.cnblogs.com/Przz/p/5409565.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值