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

  1. 3
  2. 2 2 2
  3. 1 10
  4. 10 1
  5. 2 2 2
  6. 1 1
  7. 10 10
  8.  
  9. 3 3 3
  10. 2 7
  11. 5 5
  12. 7 2

Sample Output

  1. Case 1: 2
  2. Case 2: 4
  3. Case 3: 6
  1. /*
  2. hdu 3433 A Task Process 二分+dp(卒)
  3.  
  4. dp方面毕竟若,着实没有想出来状态转移方程
  5. 主要是数据特别小,可以考虑二分答案然后通过判断来解决
  6. 如果知道了能够使用的时间limi.假设dp[i][j]表示前i个人完成j个A任务时最多能完成多少
  7. 个B任务
  8. 转移方程:
  9. dp[i][j] = (dp[i-1][j-k] + (limi-k*a[i])*b[i],dp[i][j])
  10.  
  11. hhh-2016-04-10 21:02:38
  12. */
  13. #include <iostream>
  14. #include <cstdio>
  15. #include <cstring>
  16. typedef long long ll;
  17. using namespace std;
  18. const int mod = 1e9+7;
  19. const int maxn = 205;
  20. int a[maxn],b[maxn];
  21. int x,y,n;
  22. int dp[maxn][maxn];
  23. bool cal(int limi)
  24. {
  25. //dp[i][j] 前i个人完成j个A任务的情况下,最多完成多少个B
  26. memset(dp,-1,sizeof(dp));
  27. for(int i =0; i <= x && i*a[1] <= limi; i++)
  28. {
  29. dp[1][i] = (limi-i*a[1])/b[1];
  30. }
  31.  
  32. for(int i = 2; i <= n; i++)
  33. {
  34. for(int j = 0; j <= x; j++)
  35. {
  36. for(int k = 0; k*a[i] <= limi && k <= j; k++)
  37. {
  38. if(dp[i-1][j-k] >= 0)
  39. dp[i][j] = max(dp[i][j],dp[i-1][j-k]+(limi-k*a[i])/b[i]);
  40. //如果不是同一个工人,那么工作进而同时进行
  41. }
  42. }
  43. }
  44. return dp[n][x] >= y;
  45. }
  46.  
  47. int main()
  48. {
  49. int T;
  50. int cas = 1;
  51. scanf("%d",&T);
  52. while(T--)
  53. {
  54. scanf("%d%d%d",&n,&x,&y);
  55. int ma = 0;
  56. for(int i =1 ; i <= n; i++)
  57. {
  58. scanf("%d%d",&a[i],&b[i]);
  59. ma = max(ma,a[i]);
  60. }
  61. int l = 0,r = ma*x;
  62. int ans = 0;
  63. while(l <= r)
  64. {
  65. int mid = (l+r)>>1;
  66.  
  67. if(cal(mid))
  68. {
  69. ans = mid;
  70. r = mid-1;
  71. }
  72. else
  73. l = mid + 1;
  74. }
  75. printf("Case %d: %d\n",cas++,ans);
  76. }
  77. return 0;
  78. }

  

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. python 实现cm批量上传

    import requests import json import time import random url = 'http://cm.admin.xxxx.com/customer/aj_ad ...

  2. 在ArcGIS中导出现有mxd的style文件

     做好的地图包含许多地图符号,这是之前花了很多功夫做的,怎么把它导出来再用呢?     在ArcGIS中右键工具栏,customize,选择command选项卡,在搜索框中输入style ,选择too ...

  3. salesforce零基础学习(八十七)Apex 中Picklist类型通过Control 字段值获取Dependent List 值

    注:本篇解决方案内容实现转自:http://mysalesforceescapade.blogspot.com/2015/03/getting-dependent-picklist-values-fr ...

  4. python3 常用模块

    一.time与datetime模块 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量.我们 ...

  5. 阿里云API网关(2)开放 API 并接入 API 网关

    网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...

  6. [52ABP实战课程系列]Docker&Ubuntu从入门到实战开课啦~

    任何的课程都逃不开理论的支持 久等了各位,在Asp.NET Core2.0 项目实战入门视频课程结束后,根据发起的投票信息.Docker 排在首位.按照结果,我们开始进行Docker视频课程的录制. ...

  7. jquery中attr与prop的区别

    先从一个老生常谈的问题说起,使用jquery实现全选全不选.楼主先使用的jquery版本是 jquery-1.11.1.min.js 全选<input type="checkbox&q ...

  8. python Http协议

    Http协议 一 HTTP概述 HTTP(hypertext transport protocol),即超文本传输协议.这个协议详细规定了浏览器和万维网服务器之间互相通信的规则. HTTP就是一个通信 ...

  9. Spring(一):eclipse上安装spring开发插件&下载Spring开发包

    eclipse上安装spring开发插件 1)下载安装插件包:https://spring.io/tools/sts/all 由于我的eclipse版本是mars 4.5.2,因此我这里下载的插件包是 ...

  10. Java面试题—初级(2)

    11.是否可以从一个static方法内部发出对非static方法的调用? 不可以.因为非static方法是要与对象关联在一起的,必须创建一个对象后,才可以在该对象上进行方法调用,而static方法调用 ...