A Task Process

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1332    Accepted Submission(s): 656

Problem Description
There are two kinds of tasks, namely A and B. There are 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.
 
Input
In the first line there is an integer T(T<=50), 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).

 
Output
For each test case, output “Case d: “ at first line where d is the case number counted from one, then output the shortest time to finish all the tasks.
 

Sample Input

3
2 2 2
1 10
10 1
2 2 2
1 1
10 10 3 3 3
2 7
5 5
7 2

Sample Output

Case 1: 2
Case 2: 4
Case 3: 6
/*
hdu 3433 A Task Process 二分+dp(卒) dp方面毕竟若,着实没有想出来状态转移方程
主要是数据特别小,可以考虑二分答案然后通过判断来解决
如果知道了能够使用的时间limi.假设dp[i][j]表示前i个人完成j个A任务时最多能完成多少
个B任务
转移方程:
dp[i][j] = (dp[i-1][j-k] + (limi-k*a[i])*b[i],dp[i][j]) hhh-2016-04-10 21:02:38
*/
#include <iostream>
#include <cstdio>
#include <cstring>
typedef long long ll;
using namespace std;
const int mod = 1e9+7;
const int maxn = 205;
int a[maxn],b[maxn];
int x,y,n;
int dp[maxn][maxn];
bool cal(int limi)
{
//dp[i][j] 前i个人完成j个A任务的情况下,最多完成多少个B
memset(dp,-1,sizeof(dp));
for(int i =0; i <= x && i*a[1] <= limi; i++)
{
dp[1][i] = (limi-i*a[1])/b[1];
} for(int i = 2; i <= n; i++)
{
for(int j = 0; j <= x; j++)
{
for(int k = 0; k*a[i] <= limi && k <= j; k++)
{
if(dp[i-1][j-k] >= 0)
dp[i][j] = max(dp[i][j],dp[i-1][j-k]+(limi-k*a[i])/b[i]);
//如果不是同一个工人,那么工作进而同时进行
}
}
}
return dp[n][x] >= y;
} int main()
{
int T;
int cas = 1;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&x,&y);
int ma = 0;
for(int i =1 ; i <= n; i++)
{
scanf("%d%d",&a[i],&b[i]);
ma = max(ma,a[i]);
}
int l = 0,r = ma*x;
int ans = 0;
while(l <= r)
{
int mid = (l+r)>>1; if(cal(mid))
{
ans = mid;
r = mid-1;
}
else
l = mid + 1;
}
printf("Case %d: %d\n",cas++,ans);
}
return 0;
}

  

hdu 3433 A Task Process 二分+dp的更多相关文章

  1. 二分+DP HDU 3433 A Task Process

    HDU 3433 A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  2. hdu 3433 A Task Process(dp+二分)

    题目链接 题意:n个人, 要完成a个x任务, b个y任务. 求,最短的时间 思路:由于时间较大,用 二分来找时间. dp[i][j]表示 i个人完成j个x任务, 最多能完成的y任务个数 这个题 不是很 ...

  3. hdu3433A Task Process( 二分dp)

    链接 二分时间,在时间内dp[i][j]表示截止到第i个人已经做了j个A最多还能做多少个B #include <iostream> #include<cstdio> #incl ...

  4. Codeforces 660C - Hard Process - [二分+DP]

    题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...

  5. hdu 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

  6. HDU 1024 Max Sum Plus Plus --- dp+滚动数组

    HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...

  7. HDU 1231 最大连续子序列 --- 入门DP

    HDU 1231 题目大意以及解题思路见: HDU 1003题解,此题和HDU 1003只是记录的信息不同,处理完全相同. /* HDU 1231 最大连续子序列 --- 入门DP */ #inclu ...

  8. hdu 4778 Gems Fight! 博弈+状态dp+搜索

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜 ...

  9. Hadoop:Task process exit with nonzero status of 1 异常

    在运行hadoop程序时经常遇到异常 java.io.IOException: Task process exit with nonzero status of 1.网上很多博文都说是磁盘不够的问题. ...

随机推荐

  1. Linux 复习

    shift + control + +  终端窗口放大 control + -   终端窗口缩小 ls -alh > laowang.txt 重定向,并覆盖源文件内容 ls -alh >& ...

  2. Twisted 使用多线程

    Twisted 提供主线程和辅线程,主线程只有1个,即reactor.run(),辅线程有多个,可以自由配置 Twisted 大多数代码运行在主线程中,dataReceived(),connectio ...

  3. Hibernate与mysql的对应类型

    Hibernate映射类型 Java类型 标准SQL类型  integer  java.lang.Integer  integer  long  java.lang.Long  bigint  sho ...

  4. bzoj千题计划271:bzoj4869: [六省联考2017]相逢是问候

    http://www.lydsy.com/JudgeOnline/problem.php?id=4869 欧拉降幂+线段树,每个数最多降log次,模数就会降为1 #include<cmath&g ...

  5. Microsoft dynamic 批量更新

    //批量处理 ExecuteMultipleRequest multipleRequest = new ExecuteMultipleRequest() { Settings = new Execut ...

  6. wamp的mysql设置用户名和密码

    wamp下修改mysql root用户的登录密码 感谢作者:http://www.3lian.com/edu/2014/02-25/131010.html               1.安装好wam ...

  7. python 鸭子类型

    首先Python不支持多态,也不用支持多态,python是一种多态语言,崇尚鸭子类型. 在程序设计中,鸭子类型(英语:duck typing)是动态类型的一种风格.在这种风格中,一个对象有效的语义,不 ...

  8. Electron的代码调试

    刚接触Electron,尝试调试程序时,竟无从下手,所以把这个过程做了下记录 参考工程 根据Electron的官方文档:使用 VSCode 进行主进程调试:https://electronjs.org ...

  9. mosquitto验证client互相踢

    cleint11A订阅topic#################################################### server发送topic消息 ############### ...

  10. GIT入门笔记(15)- 链接到私有GitLab仓库

    GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的功能,能够浏览源代码,管理 ...