【题目链接】: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. int*与(int*)的差别

    晚上被问到一个C++的问题: int **pa=new int* [5]; int *pb=new (int*)[5]; 上面两行代码的差别是什么? 分析与实验结果例如以下: (1)第一行代码能够在V ...

  2. B1734 [Usaco2005 feb]Aggressive cows 愤怒的牛 二分答案

    水题,20分钟AC,最大值最小,一看就是二分答案... 代码: Description Farmer John has built a <= N <= ,) stalls. The sta ...

  3. 2017-3-12 leetcode 167 209 216

    ---恢复内容开始--- 对于每次开机avast喊出的“已经检测到危害”实在忍无可忍了(它只能检测到不能根除很气..)于是重装了系统,回到了win10感觉不赖. =================== ...

  4. nginx FastCGI模块(FastCGI)配置

    http://www.howtocn.org/nginx:nginx%E6%A8%A1%E5%9D%97%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C%E4%B8%AD%E6 ...

  5. JPA设置表名和实体名,表字段与实体字段的对应

    转自:https://blog.csdn.net/LQW_java_home/article/details/53079363 首先 你的jpaProperties配置项中要有 <prop ke ...

  6. reportlab使用示例:文字和图片

    Python的reportlab专门将数据使用生成PDF中的图形和文档功能, 下载ReportLab https://pypi.python.org/simple/reportlab/ http:// ...

  7. etcd创建集群并增加节点

    下载安装 从这下载https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz tar ...

  8. 使用autofac在mvc5下依赖注入

    把遇到的问题汇总一下: 一.安装mvc5版本 命令:pm> Install-Package Autofac 结果安装的Autofac.Integration.Mvc(版本为4.0),所引用的依赖 ...

  9. js 找数组中的最值

    背景: 2个数组以下 , 比如  [[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]] 找最值的时候, ...

  10. List 常用方法解析

    1.Count属性 (获得List中元素数目) 2.Add( ) 在List中添加一个对象的公有方法 3.AddRange( ) 公有方法,在List尾部添加实现了ICollection接口的多个元素 ...