UVA10163 Storage Keepers (动态规划)
$dp[i][j]$表示前$i$个仓库由前$j$个人来守卫能取得的最大安全值;
$cost[i][j]$表示前$i$个仓库由前$j$个人来守护在能取得的最大安全值的情况下的最小花费。
AC代码
//#define LOCAL
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn = 100 + 5;
const int maxm = 30 + 5;
int a[maxm];
int dp[maxn][maxm], cost[maxn][maxm]; void solve(int n, int m) {
// init
memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
// not choose j
dp[i][j] = dp[i][j-1];
// choose j
for(int k = 1; k <= i; k++) {
int x;
if(k == i) x = a[j] / k;
else x = min(a[j] / k, dp[i-k][j-1]); if(x > dp[i][j]) {
dp[i][j] = x;
}
}
}
} memset(cost, INF, sizeof(cost));
memset(cost[0], 0, sizeof(cost[0]));
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cost[i][j] = cost[i][j-1];
for(int k = 1; k <= i; k++) {
int safe = a[j] / k;
if(safe >= dp[n][m]) {
cost[i][j] = min(cost[i][j], cost[i-k][j-1] + a[j]);
}
}
}
}
} int main() {
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
int n, m;
while(scanf("%d%d", &n, &m) == 2 && n && m) {
for(int i = 1; i <= m; i++) {
scanf("%d", &a[i]);
}
solve(n, m);
printf("%d %d\n", dp[n][m], dp[n][m]==0?0:cost[n][m]);
}
return 0;
}
如有不当之处欢迎指出!
UVA10163 Storage Keepers (动态规划)的更多相关文章
- UVA-10163 Storage Keepers (0-1背包)
题目大意:有n个仓库,m个应聘者,每人对应一个能力值.一个人可以看多个仓库,一间仓库只能被一个人看.如果一个能力为p的人看k间仓库,那么安全系数为p/k,求出最大的最小安全系数,并且求出在此情况下所有 ...
- uva10163 Storage Keepers
习题9-9 注意前提是最小值最大.很少做两次dp的题. 初始化要细心. #include<iostream> #include<cmath> #include<algor ...
- UVA-10163 Storage Keepers DP
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 10163 十六 Storage Keepers
十六 Storage Keepers Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- uva 10163 - Storage Keepers(01背包)
题目链接:10163 - Storage Keepers 题目大意:给出m为仓库的数量, 给出n为有守夜人的数量, 然后给出n个数值,为对应守夜人应付的酬劳,每个守夜人的能力与他需要的酬劳是相等的,并 ...
- UVA 10163 Storage Keepers(dp + 背包)
Problem C.Storage Keepers Background Randy Company has N (1<=N<=100) storages. Company wants ...
- UVA 10163 Storage Keepers(两次DP)
UVA 10163 Storage Keepers(两次DP) http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Ite ...
- DP(两次) UVA 10163 Storage Keepers
题目传送门 /* 题意:(我懒得写,照搬网上的)有n个仓库,m个人看管.一个仓库只能由一个人来看管,一个人可以看管多个仓库. 每个人有一个能力值pi,如果他看管k个仓库,那么所看管的每个仓库的安全值为 ...
- 【Uva 10163】Storage Keepers
[Link]: [Description] 你有n(n≤100)个相同的仓库.有m(m≤30)个人应聘守卫,第i个应聘者的能力值 为Pi(1≤Pi≤1000).每个仓库只能有一个守卫,但一个守卫可以看 ...
随机推荐
- json文件常用代码
1.json数据内容格式化处理 package com.sklm.lhb.json; public class JsonFormatTool { /** * 单位缩进字符串. */ private s ...
- py001
pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple -------------------------------- ...
- 灵雀云受邀加入VMware 创新网络,共同助力企业数字化进程
11月15日,在VMware主办的“VMware创新网络”2018高峰论坛上,VMware发布了VMware创新网络(VMwareInnovation Network,VIN)的长期发展规划和 ...
- [React Native] change port when running react native
Two ways to do that. First, use this module to do that, https://github.com/ktonon/react-native-port- ...
- arm浮点运算
首先总结一下计算机中的浮点数的存储. 浮点数的标准是IEEE-754,规定了浮点数的存储都是通过科学计算法来存储的,n2-e的表示. 浮点数首先分为,定浮点(fixed-point)和浮点(float ...
- 279. Perfect Squares(动态规划)
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...
- nmon安装与使用
一.检查安装环境 1,# uname –a (查看操作系统信息,所检查服务器为64位操作系统) Linux jmeter 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 ...
- EL有11个隐含对象
EL有11个隐含对象: 隐含对象 类型 说明 ...
- Django model 字段类型及选项解析---转载
model field 类型1.AutoField() 自增的IntegerField,通常不用自己设置,若没有设置主键,Django会自动添加它为主键字段,Django会自动给每张表添加一个自增的p ...
- Maven项目集成Jetty
1.新建webapp maven项目. 项目目录结构如下. 2.pom文件添加jetty构建. <project xmlns="http://maven.apache.org/POM/ ...