二分+DP HDU 3433 A Task Process
HDU 3433 A Task Process
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1368 Accepted Submission(s):
684
N workers and the i-th worker would like to finish one task A in ai minutes, one
task B in bi minutes. Now you have X task A and Y task B, you want to assign
each worker some tasks and finish all the tasks as soon as possible. You should
note that the workers are working simultaneously.
indicates the number of test cases.
In each case, the first line contains
three integers N(1<=N<=50), X,Y(1<=X,Y<=200). Then there are N
lines, each line contain two integers ai, bi (1<=ai, bi <=1000).
where d is the case number counted from one, then output the shortest time to
finish all the tasks.
/*
二分+DP。
二分时间t,dp[i][j]表示在时间t内前i个人完成j件A任务所能完成的B任务的最大数量。如果dp[i][x]>=y
就是可以的。然后不断迭代得到ans。
*/
#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>
#define N 70
int T,n,x,y,a[N],b[N];
void input(int &r)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
scanf("%d%d%d",&n,&x,&y);
for(int i=;i<=n;++i)
{
scanf("%d%d",&a[i],&b[i]);
r=max(r,max(a[i],b[i]));
}
}
bool check(int tim)
{
int f[]={};
memset(f,-,sizeof(f));
f[]=;
for(int i=;i<=x;++i)
if(tim>=a[]*i)
f[i]=(tim-a[]*i)/b[];
if(f[x]>=y) return true;
for(int i=;i<=n;++i)
{
for(int k=x;k>=;--k)
for(int j=k;j>=;--j)/*for(int j=0;j<=k;--j),结果更新f[i][k]的时候用的是他本身,如果改为for(int j=0;j<k;--j),又不能用f[i-1][k]来更新f[i][k],所以就改为了倒序*/
if(tim>=(k-j)*a[i]&&f[j]!=-)
f[k]=max(f[k],f[j]+(tim-a[i]*(k-j))/b[i]);
if(f[x]>=y) return true;
}
return false;
}
int find_ans(int l,int r)
{
int mid;
while(l<=r)
{
mid=(l+r)>>;
if(check(mid))
{
r=mid-;
}
else l=mid+;
}
return l;
}
int main()
{
scanf("%d",&T);
int topt=;
while(T--)
{
++topt;
int l=,r=;
input(r);
r=r**max(x,y);
printf("Case %d: %d\n",topt,find_ans(l,r));
}
return ;
}
二分+DP HDU 3433 A Task Process的更多相关文章
- hdu 3433 A Task Process 二分+dp
A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 3433 A Task Process(dp+二分)
题目链接 题意:n个人, 要完成a个x任务, b个y任务. 求,最短的时间 思路:由于时间较大,用 二分来找时间. dp[i][j]表示 i个人完成j个x任务, 最多能完成的y任务个数 这个题 不是很 ...
- Hadoop:Task process exit with nonzero status of 1 异常
在运行hadoop程序时经常遇到异常 java.io.IOException: Task process exit with nonzero status of 1.网上很多博文都说是磁盘不够的问题. ...
- Linux中的task,process, thread 简介
本文的主要目的是介绍在Linux内核中,task,process, thread这3个名字之间的区别和联系.并且和WINDOWS中的相应观念进行比较.如果你已经很清楚了,那么就不用往下看了. LINU ...
- Activity, Service,Task, Process and Thread之间的关系
Activity, Service,Task, Process and Thread之间到底是什么关系呢? 首先我们来看下Task的定义,Google是这样定义Task的:a task is what ...
- hadoop系列 第三坑: Task process exit with nonzero status of 137
跑MR的时候抛出异常: java.lang.Throwable: Child Error at org.apache.hadoop.mapred.TaskRunner.run(TaskRunner.j ...
- 2018.10.24 NOIP模拟 小 C 的数组(二分+dp)
传送门 考试自己yyyyyy的乱搞的没过大样例二分+dp二分+dp二分+dp过了606060把我自己都吓到了! 这么说来乱搞跟被卡常的正解比只少101010分? 那我考场不打其他暴力想正解血亏啊. 正 ...
- 「学习笔记」wqs二分/dp凸优化
[学习笔记]wqs二分/DP凸优化 从一个经典问题谈起: 有一个长度为 \(n\) 的序列 \(a\),要求找出恰好 \(k\) 个不相交的连续子序列,使得这 \(k\) 个序列的和最大 \(1 \l ...
- 【bzoj1044】[HAOI2008]木棍分割 二分+dp
题目描述 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍被分成了很多段,要求满足总长度最大的一段长度最小, 并且 ...
随机推荐
- FL2440驱动添加(2): RTC(Real time clock)
一,Linux下的时间分为两种,系统时间与硬件时间(RTC芯片): 1,系统时间就是运行系统能够直接看到的时间: 2,硬件时间就是RTC芯片中的时间,断电任然有电池供电: linux系统开机时,会从R ...
- Hibernate框架之注解的配置
在hibernate中,通常配置对象关系映射关系有两种,一种是基于xml的方式,另一种是基于annotation的注解方式,熟话说,萝卜青菜,可有所爱,每个人都有自己喜欢的配置方式,我在试了这两种方式 ...
- ahjesus根据身份证号码获取相关信息(生日,省市县,性别)
使用说明: //出自http://www.cnblogs.com/ahjesus 尊重作者辛苦劳动成果,转载请注明出处,谢谢! var idCard = new IdCard();var msg = ...
- mysql服务器io等待高定位与分析
这两天发现公司好几台阿里云ECS上的mysql生产服务器繁忙期间io等待高达百分之二三十(估计九成是没有write back),而且确定是mysql进程产生,由于跑的应用过多,开发和维护无法直接确定哪 ...
- Eclipse 出现Some sites could not be found. See the error log for more detail.错误 解决方法
Eclipse 出现Some sites could not be found. See the error log for more detail.错误 解决方法 Some sites could ...
- Linux_Centos中搭建nexus私服
1.在Linux下搭建Nexus私服 1).下载并且解压 下载 nexus-2.11.2-03-bundle.zip unzip nexus-2.11.2-03-bundle.z ...
- javascript小知识点
大家对input中的value值研究的透彻么,今天看到一篇博客,很神奇 然后研究了一下input中的value值到底对应的是啥值 1.input中的value,这是大家在开发中进场遇到的一个问题 & ...
- 安卓第六天笔记--ListView
安卓第六天笔记--ListView 1.AdapteView AdapteView 继承ViewGroup它的本质是容器 AdapterView派生了3个子类: AbsListView AbsSpin ...
- Java 实现多线程的三种方式
import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; public class Main { pu ...
- android 隐藏标题栏
在onCreate()方法中添加如下代码: public class FirstActivity extends Activity { @Override protected void onCreat ...