题意:

有n个员工,每个员工完成一件A任务和一件B任务的时间给出,问要完成x件A任务y件B任务所需的最短时间是多少

思路:

DP + 二分我也是第一次见到,这个我只能说太难想了,根本想不到。

dp[i][j]表示在t时间内前i个人完成j件A任务后所能完成B任务的最大数量。

代码中还有一些注释。

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int dp[][], a[], b[];
int _, n, x, y, kase = ; bool check(int t)
{
memset(dp, -, sizeof(dp));
dp[][] = ; for(int i = ; i <= n; ++i)
{
if(dp[i][x] >= y) return true;
for(int j = ; j <= x; ++j)
{
if(dp[i - ][j] != -)
{
int temp = min(t/a[i], x-j); //枚举第i个人可以做的A任务的个数
for(int k = ; k <= temp; ++k)
{
int t1 = (t - a[i] * k) / b[i]; //计算第i个人做k件A任务,所能做的B任务的个数
dp[i][j + k] = max(dp[i][j + k], dp[i - ][j] + t1); //选最优解
}
}
}
} if(dp[n][x] >= y) return true;
return false;
} int main(void)
{
#ifdef LOCAL
freopen("3433in.txt", "r", stdin);
#endif scanf("%d", &_);
while(_--)
{
scanf("%d%d%d", &n, &x, &y);
for(int i = ; i <= n; ++i)
scanf("%d%d", &a[i], &b[i]); int l = , r = a[] * x + b[] * y;
int ans = r;
while(l <= r)
{
int mid = (l + r) >> ;
if(check(mid))
{
ans = mid;
r = mid - ;
}
else l = mid + ;
} printf("Case %d: %d\n", ++kase, ans);
} return ;
}

代码君

HDU 3433 (DP + 二分) A Task Process的更多相关文章

  1. HDU 1025 DP + 二分

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1025 求最长递增子序列,O(n^2)的复杂度超时,需要优化为O(n*logn) f[i]存储长度为i的最小 ...

  2. 二分+DP HDU 3433 A Task Process

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

  3. hdu 3433 A Task Process 二分+dp

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

  4. hdu 1025:Constructing Roads In JGShining's Kingdom(DP + 二分优化)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  5. 两种解法-树形dp+二分+单调队列(或RMQ)-hdu-4123-Bob’s Race

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4123 题目大意: 给一棵树,n个节点,每条边有个权值,从每个点i出发有个不经过自己走过的点的最远距离 ...

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

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

  7. POJ-2533最长上升子序列(DP+二分)(优化版)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 41944   Acc ...

  8. Linux中的task,process, thread 简介

    本文的主要目的是介绍在Linux内核中,task,process, thread这3个名字之间的区别和联系.并且和WINDOWS中的相应观念进行比较.如果你已经很清楚了,那么就不用往下看了. LINU ...

  9. hdu2993之斜率dp+二分查找

    MAX Average Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. datepicker,结束时间必须大于开始时间

    $('#js-start-time').datepicker({ dateFormat:'yy-mm-dd', onSelect: function( startDate ) { var $start ...

  2. Redis与Memcached的incr/decr差异对比

    目前广泛使用的分布式缓存Redis和Memcached均支持对整数型Value值的增减,对应到具体命令中就是incr和decr命令. incr/decr是原子性操作(memcached 1.2.4及以 ...

  3. SGU101

    Dominoes – game played with small, rectangular blocks of wood or other material, each identified by ...

  4. 深入浅出ES6(十):集合

    作者 Jason Orendorff  github主页  https://github.com/jorendorff 前段时间,官方名为“ECMA-262,第六版,ECMAScript 2015语言 ...

  5. 使用jmeter对websocket进行压力测试[转载]

    前段时间本着练习angularJS+requireJS的目的写了一个基于nodeJS和socket.io的聊天室,github地址为:https://github.com/towersxu/node- ...

  6. MongoDB (三) MongoDB 安装

    MongoDB安装在Windows上 在 Windows上,首先要安装 MongoDB下载最新发布的MongoDB: http://www.mongodb.org/downloads 确保得到正确的版 ...

  7. POJ 1704 Staircase Nim 阶梯博弈

    #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ...

  8. Hive常用的SQL命令操作

    Hive提供了很多的函数,可以在命令行下show functions罗列所有的函数,你会发现这些函数名与mysql的很相近,绝大多数相同的,可通过describe function functionN ...

  9. 给View换字体

    注意,给View换字体是直接换.在Delegate里换的只是某一列的字体 class delegate : public QStyledItemDelegate { public: ) : QStyl ...

  10. iOS 网络请求NSURLSession

    iOS 7 和 Mac OS X 10.9 Mavericks 中一个显著的变化就是对 Foundation URL 加载系统的彻底重构. 现在已经有人在深入苹果的网络层基础架构的地方做研究了,所以我 ...