codeforces724E Goods transportation(最小割——dp)

题意:

原点汇点连所有的,流量给出,左边点连右边的,流量为c,问最大流

思路:

/* ***********************************************
Author        :devil
************************************************ */
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <cmath>
#include <stdlib.h>
#define LL long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ou(a) printf("%d\n",a)
#define pb push_back
#define mkp make_pair
template<class T>inline void rd(T &x)
{
    char c=getchar();
    x=0;
    while(!isdigit(c))c=getchar();
    while(isdigit(c))
    {
        x=x*10+c-'0';
        c=getchar();
    }
}
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
using namespace std;
const LL inf=1ll<<60;
const int mod=1e9+7;
const int N=1e4+10;
LL dp[N],s[N],p[N],c,ans;
int n;
int main()
{
    #ifndef ONLINE_JUDGE
    IN
    #endif
    rd(n),rd(c);
    rep(i,1,n) rd(p[i]);
    rep(i,1,n) rd(s[i]);
    rep(i,1,n)
    {
        dp[i]=inf;
        dep(j,i,1) dp[j]=min(dp[j-1]+s[i],dp[j]+p[i]+1ll*c*j);
        dp[0]+=p[i];
    }
    ans=dp[0];
    rep(i,1,n) ans=min(ans,dp[i]);
    printf("%I64d\n",ans);
    return 0;
}

 

posted on 2016-10-11 15:14  恶devil魔  阅读(147)  评论(0编辑  收藏  举报

导航