【题目链接】:http://codeforces.com/problemset/problem/724/E

【题意】



有n个城市;

这个些城市每个城市有pi单位的物品;

然后已知每个城市能卖掉si单位单位的物品;

且每个城市i能向城市j最多运送c单位的物品(这里j严格大于i);

问你最多能在这n个城市里面卖掉多少单位的物品;

【题解】



可以转化为最大流模型;

虚拟一个起点s和源点t;

在s和n个城市之间分别建n条边pi;

在n个城市和t之间分别建n条边si;

在n个城市之间(x,y)建n*(n-1)/2条边;这里(x< y)

然后从起点跑最大流就能得到答案;

因为n很大;

不能单纯地跑最大流;

根据最大流=最小割;

写个DP吧

每个点最后,肯定是只和s连、或者是和t连;

不可能说两条边都删掉;

则对于每个点,看他删掉的是哪条边;

/*
设f[i][j]表示前i个城市中,有j个城市和起点s相连的最小割;

f[i][j] = min(f[i-1][j-1]+s[i],f[i-1][j]+p[i]+j*c);
(删掉i和t的边,删掉i和起点s的边);
因为和起点s相连的点,可以从s到那个点
然后再到点i再到终点t,所以要多加上j*c;
即把那j条边删掉
f[i][0] = f[i-1][0]+p[i];//不能连i和s边了,即只能删掉i和s边了
f[i][i] = f[i-1][i-1]+s[i];//不能删i和s边了,即只能删掉i和t边了
*/

【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e4+100; LL f[2][N],p[N],s[N],c;
int n,now,pre; int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> n >> c;
rep1(i,1,n) cin >> p[i];
rep1(i,1,n) cin >> s[i];
rep1(i,1,n)
{
now = now^1;
f[now][0] = f[now^1][0]+p[i];
rep1(j,1,i-1)
f[now][j] = min(f[now^1][j-1]+s[i],f[now^1][j]+p[i]+j*c);
f[now][i] = f[now^1][i-1]+s[i];
}
LL ans = f[now][0];
rep1(i,1,n)
ans = min(ans,f[now][i]);
cout << ans << endl;
return 0;
}

【codeforces 724E】Goods transportation的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【31.72%】【codeforces 604B】More Cowbell

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 754D】Fedor and coupons

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. Python 远程调用MetaSploit

    (1)安装Python的msgpack类库.MSF官方文档中的数据序列化标准就是參照msgpack. root@kali:~# apt-get install python-setuptools ro ...

  2. HDU oj A + B Problem II

    郁闷了就相同的代码在HDUOJ上提交就是AC在NYOJ上提交就是WA字符串处理 #include<stdio.h> #include<string.h> #define N 1 ...

  3. webpack到底怎么用?

    webpack到底怎么用? https://www.zhihu.com/question/39290543

  4. [专辑] 也晒晒我的RBAC系统 ——行一山人的博客

    也晒晒我的RBAC系统(一):概述 也晒晒我的RBAC系统(二):系统实现原理简介 也晒晒我的RBAC系统(三):后台管理程序源码及使用演示 也晒晒我的RBAC系统(四):框架源代码(超值奉献,请勿拍 ...

  5. Cracking the Coding Interview 6.2

    There is an 8*8 chess board in which two diagnolly opposite corners have been cut off. You are given ...

  6. NOIP2013 D2T1 积木大赛

    [NOIP2013T4]积木大赛 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 noip2013day2 描述 春春幼儿园举办了一年一度的"积木大 ...

  7. NPOI导出功能

    利用NPOI组件将数据中想要的数据导出到excel表格中. demo如下 using System; using System.Collections.Generic; using System.Li ...

  8. Git Learning Part III - working remotely (Github)

    help document of Github : https://help.github.com/ 1 upload 1.1 new update  Initialize a repository  ...

  9. javascript 公历与农历相互转换工具类

    /** * 公历[1900-1-31,2100-12-31]时间区间内的公历.农历互转 * @charset UTF-8 * @Author Jea杨(JJonline@JJonline.Cn) * ...

  10. 基于S3C2440数码相框

    [参考]韦东山 教学笔记 1. 程序框架1.1 触摸屏: 主按线程,通过socket发给显示进程 --------------------------- 封装事件:ts线程 按键线程 -------- ...