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. 在phpwind内容页使用百度分享进行图片分享

    在phpwind内容页使用百度分享进行图片分享时,百度分享默认提取到的图片不一定是主题正文内容中的图片,需要使用百度提供的配置机制自行调整. 整个代码添加的位置在此不论,主要原理是在主题正文区域提取图 ...

  2. JPA(5)使用二级缓存

    jpa的缓存分为一级缓存和二级缓存,一级缓存值得是会话级别的,而二级缓存是跨会话级别的. 使用二级缓存,使用到了Ehcache,首先第一步需要在配置文件中配置使用了二级缓存 <shared-ca ...

  3. linux2.4.18内核定时器的使用

    Linux2.4下驱动中定时器的应用 我的内核是2.4.18的.Linux的内核中定义了一个定时器的结构: #include<linux/timer.h> struct timer_lis ...

  4. (旧)子数涵数·C语言——条件语句

    首先,我们讲一下理论知识,在编程中有三种结构,分别是顺序结构.条件结构.循环结构,如果用流程图来表示的话就是: 那么在C语言中,如何灵活运用这三种结构呢?这就需要用到控制语句了. 而条件语句便是控制语 ...

  5. (旧)子数涵数·VB——变量

    最近,VB吧频繁出现如下图所示的帖子(现在C吧.VB吧等都已经被二级考生玩坏了) 这主要用到的是变量的概念 首先,我们来看一下变量的数据类型 当然,就这题而言,数据类型不是重点,主要考察的是变量的作用 ...

  6. 【iOS】Quartz2D基本图形

    一.画线段 - (void)drawRect:(CGRect)rect { // Drawing code // 1.获得图形上下文 CGContextRef ctx = UIGraphicsGetC ...

  7. Fundamentals of speech signal processing

    PDF版资料下载:链接:http://pan.baidu.com/s/1hrKntkw 密码:f2y9

  8. [ASP.NET MVC] 使用Bootstrap套件

    [ASP.NET MVC] 使用Bootstrap套件 前言 在开发Web项目的时候,除了一些天赋异禀的开发人员之外,大多数的开发人员应该都跟我一样,对于如何建构出「美观」的用户接口而感到困扰.这时除 ...

  9. [Tips] Useful link ... on going

    1. CSS Bootstrap http://getbootstrap.com/ Bootstrap 中文文档 http://getbootstrap.com/2.3.2/ 最全的 Twitter ...

  10. FDO error:Failed to label layer(XXX) for class Default

    描述: A column was specified that does not exist. 出现这个问题的原因在于label features 展示的字段不存在或者为空,只要将其勾选去掉或者换个显 ...