题意:有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. 数据节点-df 无法输出结果

    1. 删除了 a 机器的/opt/data 目录 2.b与c 机器挂载了 a机器的/opt/data 3.df -h 无法输出结果 最后参考:http://blog.csdn.net/lufeisan ...

  2. 我的第一个博客——Fragment遇到的问题

    最近项目中使用fragment时遇到了一些问题: 1.fragment的刷新问题. 解决:我的情况是有多个fragment时,只需要刷新其中几个界面.之前我在网上看到的一些方法.如下: 首先在Adap ...

  3. clickableSpan实现textView文字部分点击有响应

    先定义一个clickableSpan的子类 class MyClickText extends ClickableSpan{ private Context context; public MyCli ...

  4. 梦殇 chapter four

    有人说,当你为一个问题发愁时,投掷硬币是最好的解决办法.不是因为硬币本身,而是当抛在空中时,你心里希望它落在哪面.       或许是这样吧.     时间会淡化一切记忆么,总是不相信,时间是最好的解 ...

  5. Git两分钟指南-学习入门参考

    Git两分钟指南 http://blog.jobbole.com/78999/ GIT和SVN之间的五个基本区别 http://www.oschina.net/news/12542/git-and-s ...

  6. mysql 存储过程 与 循环

    mysql 操作同样有循环语句操作,三种标准循环模式:while, loop,repeat, 外加一种非标准循环:goto [在c或c#中貌似出现过类型循环但是一般不建议用!] 一般格式为:delim ...

  7. React-router4 第二篇url-params url参数

    官方文档 以下代码均来自于官方文档 上来一步走 import React from 'react' import { BrowserRouter as Router, Route, Link } fr ...

  8. (转)Java程序员简历模板

    本简历模板由国内首家互联网人才拍卖网站「 JobDeer.com 」提供. (括号里的是我们的顾问编写的说明,建议在简历书写完成后统一删除) 先讲讲怎样才是一份好的技术简历 首先,一份好的简历不光说明 ...

  9. andorid 练习微信登陆

    AndroidManifest.xml layout1.xml <?xml version="1.0" encoding="utf-8"?> < ...

  10. UI和View 三种控制方式

    AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xm ...