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. navicat primium 12免安装版的解决方式

    https://blog.csdn.net/wanghailong_qd/article/details/85887825 工具————选项 -----环境 会发现是instantclient_10_ ...

  2. Redux action 状态

    action  不同的状态,设置不同的action.type [就是一个名字],返回对应的数据 不同的状态返回不同的  接口数据

  3. P1075 语句解析

    题目描述 一串长度不超过 255 的 PASCAL 语言代码,只有 a,b,c 3 个变量,而且只有赋值语句,赋值只能是一个一位的数字或一个变量,每条赋值语句的格式是 [变量]:=[变量或一位整数]; ...

  4. FFT NTT 错误总结(持续更新)

    FFT NTT错误总结 1 处理\(r\)数组时忘记赋值 r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1)); 2 ...

  5. freemarker<二>

    一.FreeMarker模板文件组成 ①.文本,直接输出的部分 ②.注释,即<#--...-->格式不会输出 ③.FTL指令:FreeMarker指令,和HTML标记类似,名字前加#予以区 ...

  6. python类方法、类属性和静态方法

    class Game(object): #类属性 num = 0 #实例方法 def __init__(self): #实例属性 self.name = "laowang" #类方 ...

  7. 20191017-6 alpha week 2/2 Scrum立会报告+燃尽图 05

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9802 小组名称:“组长”组 组长:杨天宇 组员:魏新,罗杨美慧,王歆瑶,徐 ...

  8. 洛谷$P2523\ [HAOI2011]\ Problem\ c$ $dp$

    正解:$dp$ 解题报告: 传送门$QwQ$ 首先港下不合法的情况.设$sum_i$表示$q\geq i$的人数,当且仅当$sum_i>n-i+1$时无解. 欧克然后考虑这题咋做$QwQ$. 一 ...

  9. $HDU$ 4352 ${XHXJ}'s LIS$ 数位$dp$

    正解:数位$dp$+状压$dp$ 解题报告: 传送门! 题意大概就是港,给定$[l,r]$,求区间内满足$LIS$长度为$k$的数的数量,其中$LIS$的定义并不要求连续$QwQ$ 思路还算有新意辣$ ...

  10. $[NOIp2015]$ 子串 $dp$

    \(Sol\) 不知道为啥看起来就很\(dp\)的亚子.我们关心的只有\(A\)串当前用到哪一个,\(B\)串已经匹配到哪个位置,已经匹配的被分成了多少段.所以设\(f_{i,j,k,0/1}\)表示 ...