POJ 2373 Yogurt factory

简单DP。

这周所用的实际花费是上一周的花费+S这周费用较小值

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;

const int maxn=10000+10;
long long c[maxn];
long long y[maxn];
long long S;
int n;

int main()
{
    while(~scanf("%d%lld",&n,&S))
    {
        for(int i=1; i<=n; i++) scanf("%lld%lld",&c[i],&y[i]);
        long long u=c[1];
        long long ans=c[1]*y[1];

        for(int i=2; i<=n; i++)
        {
            u=min(u+S,c[i]);
            ans=ans+y[i]*u;
        }
        
        printf("%lld
",ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/5296388.html