hdu 3433 A Task Process(dp+二分)
题意:n个人, 要完成a个x任务, b个y任务。
求,最短的时间
思路:由于时间较大,用 二分来找时间。
dp[i][j]表示 i个人完成j个x任务, 最多能完成的y任务个数
这个题 不是很好想, 还参考了一下大神的博客
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = +;
int d[][]; int _max(int a, int b)
{
return a>b?a:b;
}
int _min(int a, int b)
{
return a>b?b:a;
}
int main()
{
int t, i, j, k, n, x, y, ca;
int a[maxn], b[maxn];
int low, high, mid, cnt, t1;
scanf("%d", &t);
for(ca = ; ca <= t; ca++)
{
low = ;
high = ;
scanf("%d%d%d", &n, &x, &y);
for(i = ; i <= n; i++)
{
scanf("%d%d", &a[i], &b[i]);
high += x*a[i] + y*b[i];
}
while(high>low)
{
mid = (low+high)/;
memset(d, -, sizeof(d));
d[][] = ;
for(i = ; i <= n; i++)
for(j = ; j <= x; j++)
{
if(d[i-][j]!=-)
{
cnt = _min(mid/a[i], x-j);
for(k = ; k <= cnt; k++)
{
t1 = (mid-k*a[i])/b[i];
if(d[i][j+k]<d[i-][j]+t1)
d[i][j+k] = d[i-][j]+t1;
}
}
}
if(d[n][x]>=y)
high = mid;
else
low = mid+;
}
printf("Case %d: %d\n", ca, high);
}
return ;
}
hdu 3433 A Task Process(dp+二分)的更多相关文章
- 二分+DP HDU 3433 A Task Process
HDU 3433 A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- hdu 3433 A Task Process 二分+dp
A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 3586 Information Disturbing 树形DP+二分
Information Disturbing Problem Description In the battlefield , an effective way to defeat enemies ...
- HDU - 3586 Information Disturbing 树形dp二分答案
HDU - 3586 Information Disturbing 题目大意:从敌人司令部(1号节点)到前线(叶子节点)的通信路径是一个树形结构,切断每条边的联系都需要花费w权值,现在需要你切断前线和 ...
- HDU 3433 (DP + 二分) A Task Process
题意: 有n个员工,每个员工完成一件A任务和一件B任务的时间给出,问要完成x件A任务y件B任务所需的最短时间是多少 思路: DP + 二分我也是第一次见到,这个我只能说太难想了,根本想不到. dp[i ...
- 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 ...
- 两种解法-树形dp+二分+单调队列(或RMQ)-hdu-4123-Bob’s Race
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4123 题目大意: 给一棵树,n个节点,每条边有个权值,从每个点i出发有个不经过自己走过的点的最远距离 ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
随机推荐
- NodeJS - Express 4.0下使用app.dynamicHelpers错误
在NodeJS - Express 4.0下使用app.dynamicHelpers发生错误: app.dynamicHelpers({ ^ TypeError: Object function (r ...
- 服务器端spice配置详解
1. 安装必要的工具 sudo apt-get install build-essential autoconf git-core intltool 2. 安装必要的依赖包 -dev libxfixe ...
- bnuoj 4207 台风(模拟题)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4207 [题意]:中文题,略 [题解]:模拟 [code]: #include <iostrea ...
- Getting Started with Java
“学前”说明:<Learn Java for Android>这本书内容很多,都是精华,建议大家看英文版的.在这里我不打算一一总结书中的内容,书中每章节后面的exercises都很好,非常 ...
- js String Trim函数
<javascript> String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,"& ...
- 使用JAVA反射初始化数组(转)
在做JSON解析时,遇到了在不知道数组类型的前期下,需要转化为具体类型数组的问题.可以使用JAVA的反射来做. JSONArray jsonArray = (JSONArray) entry.getV ...
- win8 ubuntu
点进去看到几点注意: 1. 如果Windows是UEFI方式安装的,那Ubuntu必须也用UEFI方式安装 2. 必须用64位的Ubuntu安装文件,32位的不能探测EFI 3. 必须用UEFI的方式 ...
- app被Rejected 的各种原因翻译
1. Terms and conditions(法律与条款) 1.1 As a developer of applications for the App Store you are bound by ...
- java web项目 。classpath 文件解析
eclipse工程中.classpath文件含义: 下面是一个.classpath文件内容: < ?xml version="1.0" encoding="UTF- ...
- Unity3D TestTool Part _1
一直想看看Unity3d官方推出的UnityTestTools的测试插件,今天有空尝试了一下. 一.Quick Start 1. create a plane position which trans ...