A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.

Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i - 1 liters and costs ci roubles. The number of bottles of each type in the store can be considered infinite.

You want to buy at least L liters of lemonade. How many roubles do you have to spend?

Input

The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 109) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively.

The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 109) — the costs of bottles of different types.

Output

Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.

Example

Input
4 12
20 30 70 90
Output
150
Input
4 3
10000 1000 100 10
Output
10
Input
4 3
10 100 1000 10000
Output
30
Input
5 787787787
123456789 234567890 345678901 456789012 987654321
Output
44981600785557577

Note

In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.

In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.

In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.

题意 : 给你 n 个物品,以及一个容器的体积 l , n 个物品的体积是 2^i-1 , 求在超过容器体积的前提下,最小的花费是多少。

思路分析 : 想了一个贪心策略,优先去贪性价比最高的物品,当恰好装下的时候,此时可以记录一下答案,若不能时,此时可以让他们多装一个,再次记录一下答案,深搜就行了

代码示例:

/*
* Author: parasol
* Created Time: 2018/3/7 18:18:10
* File Name: 2.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <time.h>
using namespace std;
#define ll long long
const ll maxn = 1e6+5;
const double pi = acos(-1.0);
const ll inf = 0x3f3f3f3f; struct node
{
ll l, c;
double p;
bool operator< (const node &v)const{
return p < v.p;
}
}pre[35];
ll n, l;
ll ans = __LONG_LONG_MAX__; void dfs(ll x, ll cost, ll sum){
if (cost >= ans) return;
if (sum <= 0) {ans = min(ans, cost); return;}
if (x == n+1) return;
ll f = sum / pre[x].l;
int pt = 0;
if (sum%pre[x].l == 0){
ans = min(ans, cost+f*pre[x].c);
return;
}
else {
dfs(x+1, cost+(f+1)*pre[x].c, sum-(f+1)*pre[x].l);
pt = 1;
}
if (pt) {
dfs(x+1, cost+f*pre[x].c, sum-f*pre[x].l);
}
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n >> l;
ll an = 1;
for(ll i = 1; i <= n; i++){
scanf("%lld", &pre[i].c);
pre[i].l = an;
pre[i].p = 1.0*pre[i].c/an;
an *= 2;
}
sort(pre+1, pre+1+n);
dfs(1, 0, l);
printf("%lld\n", ans);
return 0;
}

贪心 + DFS的更多相关文章

  1. 小黑的镇魂曲(HDU2155:贪心+dfs+奇葩解法)

    题目:点这里 题目的意思跟所谓的是英雄就下100层一个意思……在T秒内能够下到地面,就可以了(还有一个板与板之间不能超过H高). 接触这题目是在昨晚的训练赛,当时拍拍地打了个贪心+dfs,果断跟我想的 ...

  2. 【bzoj3252】攻略 贪心+DFS序+线段树

    题目描述 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏. 今天他得到了一款新游戏<XX半岛>,这款游戏有n个场景(scene),某 ...

  3. hdu6060[贪心+dfs] 2017多校3

    /* hdu6060[贪心+dfs] 2017多校3*/ #include <bits/stdc++.h> using namespace std; typedef long long L ...

  4. UVALive3902 Network[贪心 DFS&&BFS]

    UVALive - 3902 Network Consider a tree network with n nodes where the internal nodes correspond to s ...

  5. 【NOIP2003】传染病控制(-贪心/dfs)

    我自己yy了个贪心算法,在某oj 0msAC~.然后去wikioi提交,呵呵,原来是之前oj的数据太弱给我水过了,我晕. 我之前的想法是在这棵树上维护sum,然后按时间来割边,每一时刻割已经感染的人所 ...

  6. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

  7. Cut 'em all! CodeForces - 982C(贪心dfs)

    K - Cut 'em all! CodeForces - 982C 给一棵树 求最多能切几条边使剩下的子树都有偶数个节点 如果n是奇数 那么奇数=偶数+奇数 不管怎么切 都会有奇数 直接打印-1 贪 ...

  8. Too Rich(贪心+DFS)

    Too Rich http://acm.hdu.edu.cn/showproblem.php?pid=5527 Time Limit: 6000/3000 MS (Java/Others)    Me ...

  9. BZOJ3252 攻略(贪心+dfs序+线段树)

    考虑贪心,每次选价值最大的链.选完之后对于链上点dfs序暴力修改子树.因为每个点最多被选一次,复杂度非常正确. #include<iostream> #include<cstdio& ...

  10. UVA 10123 No Tipping (物理+贪心+DFS剪枝)

    Problem A - No Tipping As Archimedes famously observed, if you put an object on a lever arm, it will ...

随机推荐

  1. Vue递归菜单

    一.效果图: 二.代码(Vue Cli 快速原型开发) App.vue <template> <div id="app"> <template v-f ...

  2. 在spring security3中使用自定义的MD5和salt进行加密

    首先看代码: <authentication-manager alias="authenticationManager"> <authentication-pro ...

  3. 21个项目玩转深度学习:基于TensorFlow的实践详解01—MNIST机器学习入门

    数据集 由Yann Le Cun建立,训练集55000,验证集5000,测试集10000,图片大小均为28*28 下载 # coding:utf-8 # 从tensorflow.examples.tu ...

  4. P1060 梦中的统计

    题目描述 Bessie 处于半梦半醒的状态.过了一会儿,她意识到她在数数,不能入睡. Bessie的大脑反应灵敏,仿佛真实地看到了她数过的一个又一个数.她开始注意每一个数码(0..9):每一个数码在计 ...

  5. 为什么阿里代码规约要求避免使用 Apache BeanUtils 进行属性复制

    缘起 有一次开发过程中,刚好看到小伙伴在调用 set 方法,将数据库中查询出来的 Po 对象的属性拷贝到 Vo 对象中,类似这样: 可以看出,Po 和 Vo 两个类的字段绝大部分是一样的,我们一个个地 ...

  6. 2019QLU.ACM集训队暑假训练须知

    1.每场比赛都要认认真真参与并及时记录: 2.每个队员必须做一个单独的博客页面存放自己队伍或者个人的比赛结果和补题计划: 3.比赛记录参考样式:[1]dny[2]ECNU 4.每场比赛结束都会安排一支 ...

  7. dotnet 将文件删除到回收站

    默认删除文件的时候 File.Delete 是将文件永久删除,如果是一些文档,建议删除到回收站,这样用户可以自己还原 通过 SHFileOperation 可以将文件放在回收站 本文提供的方法暂时只能 ...

  8. HDU1166 敌兵布阵 BZOJ1012 最大数[树状数组]

    一.前置知识-树状数组 树状数组(binary indexed tree)是一种简洁的代码量很小的数据结构,能够高效的处理前缀区间上的问题.在很多情况下能写树状数组解决的就不用码半天线段树了. 树状数 ...

  9. python tkinter动态追加按钮等控件可能遇到的问题

    小爬最近给同事制作一个小爬虫:具体要求: 1.每天自动定时触发: 2.模拟用户自动登陆: 3.自动爬取对应API接口数据: 4.对爬取结果进行逻辑判断,对符合条件的数据进行规则化列示: 5.列示的行项 ...

  10. Ceph 之RGW Pub-Sub Module

    Overview Pub-Sub module 顾名思义是一个发布订阅相关的模块.Pub-Sub module 为对象存储的变更事件提供一种发布-订阅机制.而发布-订阅架构本身应用非常广泛,如公有云G ...