Yogurt factory
作者:互联网
一道简单的贪心模板题
http://poj.org/problem?id=2393
将每天的价格都放到最低就行了
核心思路:第i天最低的价格 = min(第i-1天最低的价格+s,第i天原本的价格)
有了思路,代码随便打
#include <iostream> #include <algorithm> using namespace std; #define maxn 10005 typedef long long ll; ll c[maxn], y[maxn]; int main() { ll cost = 0; ll n, s; cin >> n >> s; for (ll i = 0; i < n; ++i) cin >> c[i] >> y[i]; for (ll i = 1; i < n;++i) c[i] = min(c[i], c[i - 1] + s); for (ll i = 0; i < n; ++i) cost += c[i] * y[i]; cout << cost << endl; return 0; }
标签:min,++,ll,factory,long,cost,maxn,Yogurt 来源: https://www.cnblogs.com/xdaniel/p/12236282.html