【codeforces 724E】Goods transportation
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【31.72%】【codeforces 604B】More Cowbell
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 754D】Fedor and coupons
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- WAS_集群部署应用遭遇ADMA0085E和ADMA0109W错误
原创作品,出自 "深蓝的blog" 博客.深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/47143431 近日 ...
- sizeof运算符、malloc函数及free函数
一.sizeof运算符的用法 1.sizeof运算符给出某个类型或变量在内存中所占据的字节数. int a; sizeof(a)=4; //sizeof(int)=4; double b; si ...
- JavaScript和Java的区别
一个是编译型语言(客户端平台必须有仿真器或解释器),一个是解析型语言(不经过编译,直接将文本格式的字符代码发送给浏览器解释执行). 虽然JavaScript与Java有紧密的联系,但却是两个公司开发的 ...
- Linux - 常用网络命令详解netstat,scp
ifconfig 查看生效的ip信息. [root@local ~]# ifconfig eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICA ...
- iOS10 推送通知详解(UserNotifications)
iOS10新增加了一个UserNotificationKit(用户通知框架)来整合通知相关的API,UserNotificationKit框架增加了很多令人惊喜的特性: 更加丰富的推送内容:现在可以设 ...
- Intel 的 MKL是可以用来训练的——官方的实验也提到了训练
TensorFlow如何充分使用所有CPU核数,提高TensorFlow的CPU使用率,以及Intel的MKL加速 转载 2017年09月07日 16:34:58 标签: cpu / gpu 转载 ...
- 爬虫—分析Ajax爬取今日头条图片
以今日头条为例分析Ajax请求抓取网页数据.本次抓取今日头条的街拍关键字对应的图片,并保存到本地 一,分析 打开今日头条主页,在搜索框中输入街拍二字,打开开发者工具,发现浏览器显示的数据不在其源码里面 ...
- Java 系列之spring学习--注解(三)
一.注解 使用注解之前要开启自动扫描功能 <?xml version="1.0" encoding="UTF-8"?> <beans xmln ...
- Git Learning Part I - Install Git and configure it
Why we need 'Git' GIt version control: 1. record the history about updating code and deleting code 2 ...
- windows安装pyspider
基本环境 python2.7 win7 64bit 问题 Microsoft Visual C++ 10.0 is required Microsoft Visual C++ Compiler for ...