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. Servlet3.0 Test

    1. Servlet3.0 Test and Annotation used 你可以从tomcat7中lib文件夹中找到servlet-api.jar package com.goodfan.serv ...

  2. 【背景建模】PBAS

    Pixel-Based Adaptive Segmenter(PBAS)检测算法,是基于像素的无参数模型,该算法结合了SACON和VIBE两个算法的优势,并在这两个算法的基础上改进而来,SACON和V ...

  3. DOM笔记整理及应用实例

    一.前言 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model).HTML DOM 模型被构造为对象的树 通过可编程的对象模型,JavaScript 获得了足够的 ...

  4. js实现点击<li>标签弹出其索引值

    据说这是一道笔试题,以下是代码,没什么要文字叙述的,就是点击哪个<li>弹出哪个<li>的索引值即可: <html> <head> <style& ...

  5. Vue条件渲染

    gitHub地址:https://github.com/lily1010/vue_learn/tree/master/lesson08 一 v-if显示单个元素 注意else只能跟在v-if或者v-s ...

  6. 【转】Visual Studio项目相对路径的设置,实用

    这篇文章主要写给那些以前没有用过VS的新手,同时也是自己学习经验的积累,高手就不用看了以免浪费您宝贵的时间. 在VS的工程中常常要设置头文件的包含路径,当然你可以使用绝对路径,但是如果你这样设置了你只 ...

  7. NSDictionary和NSMutableDictionary

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...

  8. 如何避免Activity 被杀死

    我们都知道,在android系统中,内存不足的时候,系统是可以杀死任何暂停.停止或者销毁的Activity.这就意味着基本上没有在前台的Activity都会面临被关闭的可能. Android系统之所以 ...

  9. JDK8 API文档(下载)

    DK API文档 java SE 8 API文档: http://www.oracle.com/technetwork/java/javase/documentation/jdk8-doc-downl ...

  10. IT技术很好的视频网址

    1.华为工程师 带你实战C++ 2.vimoe,国外的,需要FQ哦.https://vimeo.com/85831438