uva 10163 Storage Keepers (dp)
Background
Randy Company has N (1<=N<=100) storages. Company wants some men to keep them safe. Now there are M (1<=M<=30) men asking for the job. Company will choose several from them. Randy Company employs men following these rules:
1. Each keeper has a number Pi (1<=Pi<=1000) , which stands for their ability.
2. All storages are the same as each other.
3. A storage can only be lookd after by one keeper. But a keeper can look after several storages. If a keeper��s ability number is Pi, and he looks after K storages, each storage that he looks after has a safe number Uj=Pi div K.(Note: Uj, Pi and K are all integers). The storage which is looked after by nobody will get a number 0.
4. If all the storages is at least given to a man, company will get a safe line L=min Uj
5. Every month Randy Company will give each employed keeper a wage according to his ability number. That means, if a keeper��s ability number is Pi, he will get Pi dollars every month. The total money company will pay the keepers every month is Y dollars.
Now Randy Company gives you a list that contains all information about N,M,P, your task is give company a best choice of the keepers to make the company pay the least money under the condition that the safe line L is the highest.
Input
The input file contains several scenarios. Each of them consists of 2 lines:
The first line consists of two numbers (N and M), the second line consists of M numbers, meaning Pi (I=1..M). There is only one space between two border numbers.
The input file is ended with N=0 and M=0.
Output
For each scenario, print a line containing two numbers L(max) and Y(min). There should be a space between them.
Sample Input
2 1
7
1 2
10 9
2 5
10 8 6 4 1
5 4
1 1 1 1
0 0
Sample Output
3 7
10 10
8 18
0 0
최소치가 가장 크고 2분 L이다. L이 이미 알고 있는 상황에서 dp는 대응하는 Y를 구하면 된다.
#include<cstdio>
#include<map>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<set>
#include<cmath>
using namespace std;
const int maxn = 100 + 5;
const int INF = 1e9;
const double eps = 1e-6;
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
#define fi first
#define se second
int p[maxn];
int dp[maxn][maxn];
int n, m;
int solve(int ability){
if(ability==0)
return 0;
for(int i = 0;i <= m;i++){
dp[i][0] = 0;
for(int j = 1;j <= n;j++)
dp[i][j] = INF;
}
for(int i = 1;i <= m;i++){
int num = p[i]/ability;
for(int j = 1;j <= num;j++)
dp[i][j] = min(dp[i-1][j], p[i]);
for(int j = num+1;j <= n;j++){
dp[i][j] = min(dp[i-1][j], p[i]+dp[i-1][j-num]);
}
}
return dp[m][n];
}
int main(){
while(cin >> n >> m){
if(n == 0 && m == 0)
break;
for(int i = 1;i <= m;i++)
cin >> p[i];
int ans = INF;
int l = 0, r = 1000;
while(l <= r){
int mid = (l+r)/2;
int tem = solve(mid);
if(tem < INF){
ans = tem;
l = mid+1;
}
else
r = mid-1;
}
cout << r << ' ' << ans << endl;
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.