题意:有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. 10-okHttp的同步与异步

    我的理解如下: 同步: 实时的在等待返回结果: 异步:可以不是同步执行的,放入到执行队列中. 所以建议:如果需要根绝请求的结构做些判断应当用 同步,异步可能由于时间先后出现问题. /*post异步请求 ...

  2. Fresco加载显示gif图片

    第一步:首先要导包 Android Studio 或者 Gradle dependencies { compile 'com.facebook.fresco:fresco:0.6.0+' } 第二步: ...

  3. css兼容性写法大全

    淘宝初始化代码 body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset ...

  4. stark组件开发之提取公共视图函数

     路由问题, 已经解决! 然后就是视图函数的问题了: 不想重复写的解决途径就是, python  类的继承了! 写一个基类, 基类定义 增删改查. 然后其他的,全部去继承他! from django. ...

  5. JsRender 学习总结

    jsRender 三个最重要的概念:模板.容器和数据. 最重要的是:view(视图) 是我们定义的模板,上下文是视图所用的对象. 一.基础. {{:}} 和 {{>}}(或{{html:}})两 ...

  6. DNS的过程

    来自:https://www.zhihu.com/question/23042131 作者:郭无心链接:https://www.zhihu.com/question/23042131/answer/6 ...

  7. thymeleaf 格式化时间

    运用Thymeleaf模板后,前台的时间显示发生变化,和数据库不一致 HTML页面中格式如下: <td th:text="${fleeceRecord.cashmereDate}&qu ...

  8. this指针 new 和delete

    指针类型的函数:函数的返回值是指针. 不要将非静态局部地址用作函数的返回值,离开函数后就失效了 在子函数中定义局部变量后将其地址返回给函数就是非法地址 在子函数中用new操作取得的内存地址返回给主函数 ...

  9. PAT 1071 小赌怡情(15)(代码)

    1071 小赌怡情(15 分) 常言道"小赌怡情".这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注 t 个筹码后,计算 ...

  10. 20172325 2018-2019-1 《Java程序设计》第二周学习总结

    20172325 2018-2019-1 <Java程序设计>第二周学习总结 教材学习内容总结 3.1集合 集合是一种聚集.组织了其他对象的对象.集合可以分为两大类:线性集合和非线性集合. ...