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. 2017 国庆湖南 Day6

    期望得分:100+100+60=260 实际得分:100+85+0=185 二分最后一条相交线段的位置 #include<cstdio> #include<iostream> ...

  2. jquery 表双击某行时,取出某行中各列的数值.

      <script> $(function () { $("tr").dblclick(function () { var txt = $("table tr ...

  3. LeetCode & Q268-Missing Number-Easy

    Array Math Bit Manipulation Description: Given an array containing n distinct numbers taken from 0, ...

  4. Excel+DDT数据驱动实例

    一.首先安装dtt模块 数据驱动原理 1.测试数据为多个字典的list类型 2.测试类前加修饰@ddt.ddt 3.case前加修饰@ddt.data() 4.运行后用例会自动加载成N个单独的用例 二 ...

  5. jenkins简单安装及配置(Windows环境)

    jenkins是一款跨平台的持续集成和持续交付.基于Java开发的开源软件,提供任务构建,持续集成监控的功能,可以使开发测试人员更方便的构建软件项目,提高工作效率. Windows平台下,一般安装方法 ...

  6. SpringBoot应用的集成测试

    一.概念和定义 进行软件开发的时候,我们会写很多代码,不过,再过六个月(甚至一年以上)你知道自己的代码怎么运作么?通过测试(单元测试.集成测试.接口测试)可以保证系统的可维护性,当我们修改了某些代码时 ...

  7. HTTP协议扫盲(六)InputStream的复用

    一.问题提出 在进行网关引擎开发时,获取到一个http请求的inputstream后,可能要多次利用它进行read操作.由于流读过一次就不能再读了,所以需要实现InputStream的复制. 而Inp ...

  8. nodejs(1-1)

    http://www.runoob.com/nodejs/nodejs-tutorial.html

  9. 敏捷项目需求拆解&发现用户故事

    需求文档和敏捷中的Epic,User Story, Task之间是什么关系以及如何将需求文档转换成敏捷方式的描述,指导开发人员. 一直是很多公司团队比较困扰的问题,那么最近笔者为了解决这些问题,上了一 ...

  10. Python/零起点(一、数字及元组)

    Python/零起点(一.数字及元组) int整型 int()强行转换成整型数据类型 int整型是不可变,且是不可迭代的对象 一.整型数字用二进制位数表示案例: age=7 #设定一个数字赋值给age ...