(DP+二分) hdu 3433

A Task Process

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


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
 
 
并行DP
 
 
N个员工,x个A任务,y个B任务
二分时间QAQ
 
dp[i][j]前i个员工做 j个A任务得到的最多的B任务
 
注意优化QAQ
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstdlib>
#define INF 100000000
using namespace std;
int dp[205],n,x,y,a[205],b[205];
bool check(int mid)
{
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++)
    {
        int cntx=min(x,mid/a[i]);
        if(dp[x]>=y)
            return true;
        for(int j=x;j>=0;j--)
        {
            for(int k=0;k<=cntx&&(j-k)>=0;k++)
            {
                if(dp[j-k]<0)
                    continue;
                dp[j]=max(dp[j],dp[j-k]+(mid-k*a[i])/b[i]);
            }
        }
    }
    return dp[x]>=y;
}
int main()
{
    int tt,cas=1;
    scanf("%d",&tt);
    while(tt--)
    {
        int ans=0;
        scanf("%d%d%d",&n,&x,&y);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i],&b[i]);
        }
        int l,r;
        l=0,r=INF;
        while(l<=r)
        {
            int mid;
            mid=(l+r)>>1;
            if(check(mid))
            {
                ans=mid;
                r=mid-1;
            }
            else
                l=mid+1;
        }
        printf("Case %d: %d
",cas++,ans);
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/water-full/p/4510236.html