poj 1973 erf

Software Company

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0
Problem Description
A software developing company has been assigned two programming projects. As both projects are within the same contract, both must be handed in at the same time. It does not help if one is finished earlier. 

This company has n employees to do the jobs. To manage the two projects more easily, each is divided into m independent subprojects. Only one employee can work on a single subproject at one time, but it is possible for two employees to work on different subprojects of the same project simultaneously. 

Our goal is to finish the projects as soon as possible. 
 

Input
The first line of the input file contains a single integer t (1 <= t <= 11), the number of test cases, followed by the input data for each test case. The first line of each test case contains two integers n (1 <= n <= 100), and m (1 <= m <= 100). The input for this test case will be followed by n lines. Each line contains two integers which specify how much time in seconds it will take for the specified employee to complete one subproject of each project. So if the line contains x and y, it means that it takes the employee x seconds to complete a subproject from the first project, and y seconds to complete a subproject from the second project.
 

Output
There should be one line per test case containing the minimum amount of time in seconds after which both projects can be completed.
 

Sample Input
  
  
1 3 20 1 1 2 4 1 6
 

Sample Output
  
  
18
 
dp[i][j]表示在tim的时间内前i个员工做了a软件j个之后所能做的b软件的最大值,dp里面的是b软件的最大值,那个tim是二分时间得来的。可以想得通:当tim增加的时候,dp[i][j]一定是不减的,所以可以二分时间。当dp[n][m]>=m也就是n个员工在tim的时间内做了m个a软件以及超过m的b软件,所以,假定的时间tim就可以缩小。至于dp[i][j]的状态转移:
dp[i][j]=max{dp[i][j],dp[i-1][j-k]+(tim-k*a[i])/b[i]};(tim-k*a[i])/b[i]表示分配给第i个员工k件a软件然后在tim时间内做完的b软件的个数。
#include<iostream>  
#include<cstring>  
#include<algorithm>
using namespace std;  
int dp[105],a[105],b[105]; 
bool ok(int n,int mid,int m)
{
	int i,j,k;
	memset(dp,-1,sizeof(dp));
	 //初始化第一个人  
    for (i = 0; i <= m; i++)  
    {  
        if (mid< i * a[i])  
            break;  
        dp[i] = max(dp[i], (mid - i * a[1]) / b[1]);  
    }  
    if (dp[m] >= m)  
        return true;  
    //对于每一个人  
    for (i = 2; i <= n; i++)  
    {  
        //做j项A时的最大值,从大到小按照状态方程刷新状态  
        for (j = m; j >= 0; j--)  
        {  
            //遍历做0-k的所有子情况,即当前第i个人做了k个A项目  
            for (k = 0; k <= j; k++)  
            {  
                if (mid < k * a[i])  
                    break;  
                if (dp[j - k] != -1)  
                {  
                    dp[j] = max(dp[j], dp[j - k] + (mid - k * a[i]) / b[i]);  
                }  
            }  
        }  
        if (dp[m] >= m)  
            return true;  
    }  
    return false;  
}
int main()  
{
	int t;
	cin>>t;
	while(t--)
	{
		int m,n,i,j,low=0,high=0;
		cin>>n>>m;
		for(i=1;i<=n;++i)
		{
			cin>>a[i]>>b[i];
			high=max(high,max(a[i],b[i]));
		}
		high=high*m*2;   //二分查找的上限 
		int mid,ans=high;
		while(low<=high)
		{
			mid=(low+high>>1);
			if(ok(n,mid,m))
			{
				ans=mid;
				high=mid-1;
			}
			else
				low=mid+1;
		}
		cout<<ans<<endl;
	}
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值