题意:有n个仓库,m个管理员,每个管理员有一个能力值P,每个仓库只能由一个管理员看管,但是每个管理员可以看管k个仓库(但是这个仓库分配到的安全值只有p/k,k=0,1,...),雇用的管理员的工资即为他们的能力值p和,问,使每个仓库的安全值最高的前提下,使的工资总和最小。

析:首先使用二分安全值,然后使用DP来判断是不是能够达到这个安全值,这个DP就是一个01背包,dp[i] 表示看管 i 个仓库的最少费用多少,dp[j] = min{dp[j], d[j-x] + cost[i]}。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
//#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("in.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1100 + 10;
const int maxm = 1e5 + 10;
const int mod = 50007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r > 0 && r <= n && c > 0 && c <= m;
} int a[maxn], b[maxn];
int dp[maxn];
int ans; bool judge(int mid, bool ok){
ms(dp, INF); dp[0] = 0;
for(int i = 0; i < m; ++i){
int x = a[i] / mid;
for(int j = 1050; j >= x; --j)
dp[j] = min(dp[j], dp[j - x] + a[i]);
}
int res = INF;
for(int i = n; i <= 1050; ++i)
res = min(res, dp[i]);
if(ok) ans = res;
return res != INF;
} int main(){
while(scanf("%d %d", &n, &m) == 2 && n+m){
int l = 1, r = 0;
for(int i = 0; i < m; ++i) scanf("%d", a + i), r = max(r, a[i]);
while(l <= r){
int m = l + r >> 1;
if(judge(m, false)) l = m + 1;
else r = m - 1;
}
if(l == 1){ printf("0 0\n"); continue; }
judge(l - 1, 1);
printf("%d %d\n", l - 1, ans);
}
return 0;
}

  

UVa 10163 Storage Keepers (二分 + DP)的更多相关文章

  1. UVA 10163 - Storage Keepers(dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题意 有n个仓库,让m个人来看管.一个仓库只能由一个人来看管,一个人可以看管多个仓库. 每个人 ...

  2. UVA 10163 Storage Keepers(两次DP)

    UVA 10163 Storage Keepers(两次DP) http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Ite ...

  3. DP(两次) UVA 10163 Storage Keepers

    题目传送门 /* 题意:(我懒得写,照搬网上的)有n个仓库,m个人看管.一个仓库只能由一个人来看管,一个人可以看管多个仓库. 每个人有一个能力值pi,如果他看管k个仓库,那么所看管的每个仓库的安全值为 ...

  4. uva 10163 - Storage Keepers(01背包)

    题目链接:10163 - Storage Keepers 题目大意:给出m为仓库的数量, 给出n为有守夜人的数量, 然后给出n个数值,为对应守夜人应付的酬劳,每个守夜人的能力与他需要的酬劳是相等的,并 ...

  5. UVA 10163 Storage Keepers(dp + 背包)

    Problem C.Storage Keepers  Background Randy Company has N (1<=N<=100) storages. Company wants ...

  6. uva 10163 Storage Keepers

    题意: 有n个仓库,m个人,一个仓库只能由一个人托管,每个人可以托管多个仓库. 每个人有一个能力值a,如果说他托管了k个仓库,那么这些仓库的安全值都是a/k. 雇佣一个人的花费也是a. 如果一个仓库没 ...

  7. UVA 10163 十六 Storage Keepers

    十六 Storage Keepers Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  8. 二分+DP HDU 3433 A Task Process

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

  9. hdu 3433 A Task Process 二分+dp

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

随机推荐

  1. 使用pyqt写了一个检查大数据环境的gui

    通过pyqt做了一个大数据最佳实践检查的gui界面 1.首先是需要用到的模块 from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets ...

  2. swift - 本地通知

    1. AppDelegate  注册 class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? fun ...

  3. Android系统显示原理

    Android的显示过程可以概括为:Android应用程序把经过测量.布局.绘制后的surface缓存数据,通过SurfaceFlinger把数据渲染到屏幕上,通过Android的刷新机制来刷新数据. ...

  4. Js学习(1)基本语法

    变量: 用var声明变量,如果只是声明变量而不赋值,则变量的值是undefined,表示无定义 不写·var也有效,但不建议 变量声明两次无效,但第二次声明时赋值会覆盖掉前面的值 变量提升: Js引擎 ...

  5. mysql left join 多条记录 1:n 的处理方法

    一.准备两张表,文章表和评伦表 CREATE TABLE `article` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', ...

  6. 【MINA学习笔记】—— 1.体系结构分析[z]

    前言 Apache的MINA框架是一个早年非常流行的NIO框架,它出自于Netty之父Trustin Lee大神之手.虽然目前市场份额已经逐渐被Netty取代了,但是其作为NIO初学者入门学习框架是非 ...

  7. bootstrap collapse 无法收回

    $(function () { //修复collapse不能正常折叠的问题 $(".collapsed").click(function () { var itemHref = $ ...

  8. pyton random 模块

    import random print(random.random())#(0,1)----float 大于0且小于1之间的小数 print(random.randint(1,3)) #[1,3] 大 ...

  9. C#委托深入学习

    一基础学习: .Net delegate类型:委托跟回调函数是很有渊源的.回调其实跟通知机制有关,考虑这样一个基本的事件序列: a对象调用了b对象的某个方法,希望b对象在其方法完成之时调用a对象的某个 ...

  10. 引爆你的Javascript代码进化

    转自:http://www.hicss.net/evolve-your-javascript-code/ 方才在程序里看到一段JS代码,写法极为高明,私心想着若是其按照规范来写,定可培养对这门语言的理 ...