2502. 买珍珠
Constraints
Time Limit: 1 secs, Memory Limit: 256 MB
Description
珍珠市场上有
N(
N ≤ 100)种等级的珍珠,每种珍珠的需求数量是
Bi,单位价格是
Pi。
不幸的是,这个市场是黑市——购买一种珍珠,需要额外多付10个同种珍珠的钱(如果不购买当然不用)。
针对这种情况,我们可以用高等级的珍珠来代替低等级的珍珠。
举个例子,
需要5个等级1的珠子(单位价格10元)、100个等级2的珠子(单位价格20元)。按照正常情况下购买需要花费 ( 5 +10 ) * 10 + ( 100 + 10 ) * 20 = 2350 元,如果用等级2的珠子代替等级1的珠子,只需要花费 ( 5 + 100 + 10 ) * 20 = 2300 元。
现在的问题是,应该如何购买珍珠才能在满足需求的条件下花费最少。
Input
第一行,一个整数
N,表示珍珠等级总数。
第二行,
N个整数,按照等级从低到高描述每种珍珠的需求数量。
第二行,
N个整数,按照等级从低到高描述每种珍珠的单位价格。
(当然价格也是递增的)。
Output
一个整数,表示最少花费。
Sample Input
2 5 100 10 20
Sample Output
2300
Problem Source
黄金周赛——省赛最后的冲刺
// Problem#: 2502
// Submission#: 3233236
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <vector>
#include <iomanip>
#include <map>
#include <stack>
#include <functional>
#include <list>
#include <cmath>
using namespace std;
#define MAX 105
int main() {
std::ios::sync_with_stdio(false);
int needNum[MAX], val[MAX], cost[MAX];
int n;
cin >> n;
needNum[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> needNum[i];
needNum[i] += needNum[i - 1];
}
for (int i = 1; i <= n; i++) cin >> val[i];
for (int i = 1; i <= n; i++) {
cost[i] = val[i] * (needNum[i] + 10);
for (int j = 1; j < i; j++) {
if (cost[j] + (needNum[i] - needNum[j] + 10) * val[i] < cost[i]) cost[i] = cost[j] + (needNum[i] - needNum[j] + 10) * val[i];
}
}
cout << cost[n] << endl;
//getchar();
//getchar();
return 0;
}