二分+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根木棍被分成了很多段,要求满足总长度最大的一段长度最小, 并且 ...
随机推荐
- Retention、Documented、Inherited三种注解
Retention注解 Retention(保留)注解说明,这种类型的注解会被保留到那个阶段. 有三个值:1.RetentionPolicy.SOURCE —— 这种类型的Annotations只在源 ...
- 开源VS扩展CodeMaid介绍
CodeMaid是一个开源的Visual Studio的扩展插件,用于整理与优化代码等.功能类似于商业软件ReSharper,但它是免费的,并且开放源代码.它能帮助你更容易的理解你的代码,支 ...
- java LinkedBlockingQueue和ConcurrentLinkedQueue的区别
实现上看,两者都继承于AbstractQueue,但是ConcurrentLinkedQueue实现了Queue,而LinkedBlockingQueue实现了BlockingQueue,Blocki ...
- jQuery实现图片伦播效果(淡入淡出+左右切换)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 备份一张iPhone拍照写入exif中的orientation图片
- Echarts图表控件使用总结2(Line,Bar)—问题篇
Echarts图表控件使用总结1(Line,Bar):http://www.cnblogs.com/hanyinglong/p/Echarts.html 1.前言 a.前两天简单写了一篇在MVC中如何 ...
- margin和padding对行内元素的影响
这个是在面试的时候,面试官问我的一个小问题 自己没有考虑过inline元素设置margin和padding的问题 学习的过程记录下来 1)inline元素的高度是由元素的内容决定的(字体的大小和行高) ...
- 如何rename sqlserver database
Problem Sometimes there is a need to change the name of your database whether this is because the or ...
- 照着别人的demo自己试着做了个放大镜效果
原理: A:放大镜 B:小图片 C:大图片可视区域 D:大图片 鼠标的位置应该在放大镜的中央,所以鼠标位置为:clientX=A.offsetLeft()+B.offsetLeft+1/2*A.o ...
- Lync 客户端:无法登陆到Lync,验证服务器中的证书时遇到问题
安装完Lync客户端后,运行时Lync客户端时,报出如下错误: [原因解析] Lync客户端没有正确安装CA证书链. [解决办法] 第一种方法:将计算机加入域. 第二种方法:不加入域的处理方法: 1. ...