Software Company

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 1112   Accepted: 482

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,f[i][j]表示是前i个人做j个A项目所能做的最多的B项目的数目,
方程:d[i][j] = max { d[i][j] , d[i][j - k] + (time - A[i] * k) / B[i] }
枚举第i个人做k个A项目,剩下的时间用来做B项目,只要检查d[i][m]》=m就是能够到这个时间。
当然我们也可以用滚动数组压缩空间。*/
#define N 101
#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>
struct QU{
int n,m,A[N],B[N],f[N];
void init(int x,int y)
{
n=x;m=y;
memset(A,,sizeof(A));
memset(B,,sizeof(B));
memset(f,,sizeof(f));
}
void add(int a,int b,int i)
{
A[i]=a;B[i]=b;
}
bool check(int V)
{
memset(f,-,sizeof(f));
for(int i=;i<=m;++i)
{/*初始化第一个人的做i个A项目的情况*/
if(i*A[]>V) break;
f[i]=max(f[i],(V-i*A[])/B[]);
}
if(f[m]>=m) return true;
for(int i=;i<=n;++i)
{
for(int j=m;j>=;--j)
{/*枚举前i-1人做了多少个A*/
for(int k=;k<=j;++k)
{/*枚举第i个人做了k个A项目*/
if(V<k*A[i]) break;
if(f[j-k]!=-)
f[j]=max(f[j],f[j-k]+(V-k*A[i])/B[i]);
/*注意前-1个人可能做不到j-k个项目,这时候如果转移,那就是前i-1个人总共花了-1时间,显然不合题意*/
}
}
if(f[m]>=m) return true;
}
return false;
}
}Q;
int main()
{
int tes;
scanf("%d",&tes);
int n,m;
while(tes--)
{
scanf("%d%d",&n,&m);
Q.init(n,m);
int a,b;
int maxx=-;
for(int i=;i<=n;++i)
{
scanf("%d%d",&a,&b);
Q.add(a,b,i);
maxx=max(maxx,max(a,b));
}
int l=,r=maxx*m*;
int mid;
while(l<=r)
{
mid=(l+r)>>;
if(Q.check(mid))
r=mid-;
else l=mid+;
}
printf("%d\n",l); }
return ;
}

二分+动态规划 POJ 1973 Software Company的更多相关文章

  1. Poj 1973 Software Company(二分+并行DP)

    题意:软件公司接了两个项目,来自同一个合同,要一起交付.该公司有n个程序猿来做这两个项目A和B,每个项目都被分为m个子项目,给定每个程序猿做一个A中的子项目需要的时间Xi秒,和做B中的子项目所需时间Y ...

  2. 任务调度分配题两道 POJ 1973 POJ 1180(斜率优化复习)

    POJ 1973 这道题以前做过的.今儿重做一次.由于每个程序员要么做A,要么做B,可以联想到0/1背包(谢谢N巨).这样,可以设状态 dp[i][j]为i个程序员做j个A项目同时,最多可做多少个B项 ...

  3. 搜索+剪枝 POJ 1416 Shredding Company

    POJ 1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5231   Accep ...

  4. POJ 3216 Repairing Company(最小路径覆盖)

    POJ 3216 Repairing Company id=3216">题目链接 题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间 ...

  5. poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)

    http://poj.org/problem?id=3216 Repairing Company Time Limit: 1000MS   Memory Limit: 131072K Total Su ...

  6. poj 3216 Repairing Company

    http://poj.org/problem?id=3216 n个地点,m个任务 每个任务有工作地点,开始时间,持续时间 最少派多少人可以完成所有的任务 传递闭包之后最小路径覆盖 #include&l ...

  7. POJ 1416 Shredding Company【dfs入门】

    题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  8. 【折半枚举+二分】POJ 3977 Subset

    题目内容 Vjudge链接 给你\(n\)个数,求出这\(n\)个数的一个非空子集,使子集中的数加和的绝对值最小,在此基础上子集中元素的个数应最小. 输入格式 输入含多组数据,每组数据有两行,第一行是 ...

  9. 【二分】POJ 2109

    谁骗我这是贪心TT 大概就是求k的n次方等于p时的k(k到10^9),由于,p的数据到了10^101,n到200,所以直接算估计T ?? 反正看完想到二分,其实数据要是再大点估计我这个二分不行. 网上 ...

随机推荐

  1. LeetCode1:Two Sum

    题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...

  2. [c#] const 与 readonly

    c# 中 const 与 readonly 关键字看似相同,实则不同.重点在于确定值的时间. const const 很简单,就是一个常量,不可以被 static 修饰,因为被 const 修饰的字段 ...

  3. [moka同学笔记]Yii2.0验证码

    1.Model中Code.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/07/25 * Time: 10:48 ...

  4. Python on VS Code

    install python extension Press F1, and input "ext install python". Then the icon at the le ...

  5. PHP KMP算法实现

    function getNext( $str ){ $ret = array(0=>0); for( $j =1; $j < strlen($str); $j++ ){ $_s = sub ...

  6. [小北De编程手记] : Lesson 01 - Selenium For C# 之 环境搭建

    在我看来一个自动化测试平台的构建,是一种很好的了解开发语言,单元测试框架,自动化测试驱动,设计模式等等等的途径.因此,在下选择了自动化测试的这个话题来和大家分享一下本人关于软件开发和自动化测试的认识. ...

  7. Force.com微信开发系列(七)OAuth2.0网页授权

    OAuth是一个开放协议,允许用户让第三方应用以安全且标准的方式获取该用户在某一网站上存储的私密资源(如用户个人信息.照片.视频.联系人列表),而无须将用户名和密码提供给第三方应用.本文将详细介绍OA ...

  8. MX4连接后adb无法识别解决方法

    1. 使用android SDK目录中的 android SDK目录\tools 下的android脚本,命令行中执行 android update adb,成功运行后,会在用户名录下产生,C:\Us ...

  9. 在Mac上配置Android adb命令

    一 adb定义: adb(android debug bridge)是android系统中的一种命令行工具,通过它可以和android设备或模拟器通信. 二 在Mac上的配置过程 启动终端 进入当前用 ...

  10. 介绍一种css水平垂直居中的方法(非常好用!)

    这次介绍一下一个水平垂直居中的css方法,这个方法可以说是百试百灵,废话不多说,直接附上代码: html,body{ width:100%; height:100%; } 你需要居中的元素{ posi ...