二分+动态规划 POJ 1973 Software Company
Software Company
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 1112 | Accepted: 482 |
Description
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
Output
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的更多相关文章
- Poj 1973 Software Company(二分+并行DP)
题意:软件公司接了两个项目,来自同一个合同,要一起交付.该公司有n个程序猿来做这两个项目A和B,每个项目都被分为m个子项目,给定每个程序猿做一个A中的子项目需要的时间Xi秒,和做B中的子项目所需时间Y ...
- 任务调度分配题两道 POJ 1973 POJ 1180(斜率优化复习)
POJ 1973 这道题以前做过的.今儿重做一次.由于每个程序员要么做A,要么做B,可以联想到0/1背包(谢谢N巨).这样,可以设状态 dp[i][j]为i个程序员做j个A项目同时,最多可做多少个B项 ...
- 搜索+剪枝 POJ 1416 Shredding Company
POJ 1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5231 Accep ...
- POJ 3216 Repairing Company(最小路径覆盖)
POJ 3216 Repairing Company id=3216">题目链接 题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间 ...
- poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)
http://poj.org/problem?id=3216 Repairing Company Time Limit: 1000MS Memory Limit: 131072K Total Su ...
- poj 3216 Repairing Company
http://poj.org/problem?id=3216 n个地点,m个任务 每个任务有工作地点,开始时间,持续时间 最少派多少人可以完成所有的任务 传递闭包之后最小路径覆盖 #include&l ...
- POJ 1416 Shredding Company【dfs入门】
题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Tot ...
- 【折半枚举+二分】POJ 3977 Subset
题目内容 Vjudge链接 给你\(n\)个数,求出这\(n\)个数的一个非空子集,使子集中的数加和的绝对值最小,在此基础上子集中元素的个数应最小. 输入格式 输入含多组数据,每组数据有两行,第一行是 ...
- 【二分】POJ 2109
谁骗我这是贪心TT 大概就是求k的n次方等于p时的k(k到10^9),由于,p的数据到了10^101,n到200,所以直接算估计T ?? 反正看完想到二分,其实数据要是再大点估计我这个二分不行. 网上 ...
随机推荐
- 模块在insmod之后无法rmmod问题
1,首先保证make menuconfig选项配置: [*] Enable loadable module support ---> [*] Module unloading 2,在lib ...
- UVA 10090 - Marbles 拓展欧几里得
I have some (say, n) marbles (small glass balls) and I am going to buy some boxes to store them. The ...
- #define lowbit(x) ((x)&(-x))原理详解
#define lowbit(x) ((x)&(-x)) 也可以写成如下形式: int Lowbit(x) { return x&(-x); } 例如: 1> x = 1: 十进 ...
- javascript 之拼接html字符串
// var one = {"id":1, "leasetime":2, "ney":0,"myhuifangshi": ...
- Java 进程占用 VIRT 虚拟内存超高的问题研究
1. 现象 最近发现线上机器 java 8 进程的 VIRT 虚拟内存使用达到了 50G+,如下图所示: 2. 不管用的 -Xmx 首先第一想到的当然使用 java 的 -Xmx 去限制堆的使用.但是 ...
- Q:关于Outlook for CRM 中预览记录窗体的设置
问题: 如何在Outlook for CRM中,将实体记录的预览窗口的信息做调整? 解决方案: 在Outlook里,在打开实体后选择View=>Customize Reading Pane,这里 ...
- 【转载】菜鸟Ubuntu下安装Android Studio
原文:http://forum.android-studio.org/forum.php?mod=viewthread&tid=236&extra=page%3D1%26filter% ...
- Eclipse环境下配置spket中ExtJS5.0提示
使用eclipse编写extjs时,一定会用到spket这个插件,spket可以单独当作ide使用,也可以当作eclipse插件使用,我这里是当作eclipse的插件使用的,下面来一步步图解说明如何配 ...
- C++中const用法总结
1修饰变量/指针 注意以下几种修饰的区别: (1)const int * a; (2)int const *a; (3)int * const b; (4)int const* const c; 其中 ...
- Python文件操作之简化代码
一朝误入此门中,从此红尘了如空.... 程序这条路,当真是路漫漫... 这两天找到一本书,名为<笨方法学Python第三版>,全实例,感觉挺好的.需要的点书名下载, 密码:gmpn 今天想 ...