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. tornado 采用 epoll 代理构建高并发网络模型

    1 阻塞和非阻塞  对于阻塞和非阻塞,网上有一个很形象的比喻,就是说好比你在等快递,阻塞模式就是快递如果不到,你就不能做其他事情.非阻塞模式就是在这段时间里面,你可以做其他事情,比如上网.打游戏.睡觉 ...

  2. Java 后端微信小程序支付demo (网上说的坑里面基本上都有)

    Java 后端微信小程序支付 一.遇到的问题 1. 商户号该产品权限未开通,请前往商户平台>产品中心检查后重试 2.签名错误 3.已经调起微信统一下单接口,可以拿到预支付ID,但是前端支付的时候 ...

  3. Spark性能优化总结

    1. 避免重复加载RDD 比如一份从HDFS中加载的数据 val rdd1 = sc.textFile("hdfs://url:port/test.txt"),这个test.txt ...

  4. ES6常用新特性

    https://segmentfault.com/a/1190000011976770?share_user=1030000010776722 该文章为转载文章!仅个人喜好收藏文章! 1.前言 前几天 ...

  5. idea导入本地maven项目

    首先把项目关闭File->Close Project 否则会将项目导入到当前项目中 回到主界面,点击Import Project 一定要选择项目的pom文件 默认设置,继续往下走 默认配置,下一 ...

  6. LeetCode & Q28-Implement strStr-Easy

    String Two Pointers Description: Implement strStr(). Returns the index of the first occurrence of ne ...

  7. FTP传输文件被破坏的问题(Linux、Busybox)

    在网络设备上抓包后,通过FTP传输到本机,发现抓包文件破坏.更换tftp后文件正常,定位问题在FTP上. FTP的传输模式有两种:①ASCII  ②二进制 ①ASCII: 以ASCII编码的方式传输文 ...

  8. MySQL一些中重要命令

    前言: 最近在面试的过程中,深感对MySQL一些重要命令的缺失.借着这个机会,补补这块的知识.不让自己只会增删查改,懂一些高级的东西 limit 用法 order by 用法 in 和 between ...

  9. First:安装配置JDK and 部署Tomcat

    (一)准备 百度云地址(win,64Bit): 1.tomcat(7.0):链接:https://pan.baidu.com/s/1f60DOGO5Hnj9bq-987FNrw 密码:6q55 2.j ...

  10. pandas.DataFrame.describe 官方文档翻译percentile_width,percentiles,include, exclude

     使用格式:DataFrame.describe(percentile_width=None, percentiles=None, include=None, exclude=None)  作用:生成 ...