## Hello 2018 C. Party Lemonade ##

## Hello 2018 C. Party Lemonade ##
http://codeforces.com/contest/913/problem/C

  • 算法:贪心
  • 思路:
    • 求出每个2^(i-1)体积对应下的最小cost(利用倍数关系遍历一遍)
    • 从最大体积的瓶子开始买,因为瓶子不可分割,可用 (L+v-1)/v 表示:当前只购买体积v并确保填满L的,所需瓶数(多买一点可能更便宜)L为剩余所需体积数
#include <bits/stdc++.h>
#define pi acos(-1)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL ll_INF = 0x3f3f3f3f3f3f3f3f;//4e18 ~= 2^62
const int N =1000 + 10;
const LL mod = 1e9+7;注意mod 为longlong
LL c[N];


int main()
{
    int n, l;
    scanf("%d%d" ,&n, &l);
    for(int i=1; i<=n; i++){
        scanf("%d", &c[i]);
    }
    for(int i=2; i<=n; i++){
        c[i] = min(c[i]*1LL, 2LL*c[i-1]);
    }
    LL ans=ll_INF, anss=0;
    for(int i=n; i>=1; i--){
        LL v = 1LL<<i-1;
        ans = min(ans, anss+(l+v-1LL)/v*c[i]);
        anss += l/v*c[i];
        l-=l/v*v;
    }
    printf("%I64d\n", ans);
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值