Sicily 2502. 买珍珠

2502. 买珍珠

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

珍珠市场上有 NN ≤ 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;
}                                 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值