## Hello 2018 C. Party Lemonade ##
2018-01-23 11:59
393 查看
## Hello 2018 C. Party Lemonade ##
http://codeforces.com/contest/913/problem/C
算法:贪心
思路:
求出每个2^(i-1)体积对应下的最小cost(利用倍数关系遍历一遍)
从最大体积的瓶子开始买,因为瓶子不可分割,可用 (L+v-1)/v 表示:当前只购买体积v并确保填满L的,所需瓶数(多买一点可能更便宜)L为剩余所需体积数
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 ; 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); }
相关文章推荐
- Codeforces Hello 2018 - C - Party Lemonade
- Hello 2018 C. Party Lemonade (dp好题)
- Codeforces Hello 2018——Party Lemonade(DP)
- Hello 2018 C - Party Lemonade
- Codeforces Hello 2018 C. Party Lemonade(思维)
- Hello 2018 C. Party Lemonade(二进制技巧+dp思想)
- Codeforces Hello 2018 C. Party Lemonade 贪心、优先队列
- Hello 2018-C. Party Lemonade
- 【Hello 2018 C】Party Lemonade
- Codeforces Hello 2018 [ABC]
- Hello 2018-B. Christmas Spruce
- Hello 2018 E. Logical Expression(dp)
- codeforces Hello 2018(A-E)
- Hello 2018 B. Christmas Spruce
- Hello 2018 B. Christmas Spruce 水题
- Hello 2018(B、C)
- CF hello 2018(A~E)
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) E - Party
- Codeforces Hello 2018 - A - Modular Exponentiation
- Hello 2018 A