【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) = ...
随机推荐
- UVA - 10029 Edit Step Ladders (二分+hash)
Description Problem C: Edit Step Ladders An edit step is a transformation from one word x to another ...
- Window上python 开发--1.搭建开发环境
事实上在开发python最好在ubuntu环境下,简单也便于扩展各个package.可是我的linux的电脑临时不在身边.还的我老婆的电脑win7没办法啊. 因为python的跨平台性.在window ...
- oc7--内存分析
// // main.m // 第二个OC类 #import <Foundation/Foundation.h> @interface Person : NSObject { @publi ...
- 架构-Eureka:第一个方法
ylbtech-架构-Eureka:第一个方法 工程介绍 Spring Cloud 工程目录 model registry-center Servers tzxyfx tzxyfx-provider ...
- Java基础学习分享
一.Java介绍 Java是由原Sun公司(现已被甲骨文公司收购)于1991年开发的编程语言,初衷是为智能家电的程序设计提供一个分布式代码系统.为了使整个系统与平台无关,采用了虚拟机器码方式,虚拟机内 ...
- docker(部署常见应用):docker部署mysql
上节回顾:docker(部署常见应用):docker部署nginx docker部署mysql:5.7.26 # 下载镜像 docker pull mysql: # 查看镜像 docker image ...
- wordpress插件推荐
以下插件可以全部到后台插件中心安装,只需使用关键词搜索即可 安全插件:Wordfence Security 后台增加一道密码:Stealth Login Page 隐藏后台登录地址:WPS-Hide- ...
- 【MFC】虚拟键代码
一:首先介绍键盘消息 系统消息: ALT,F1,——F24等,是由系统内部处理的,程序本身就存在,比如F1是帮助键. WM_SYSKEYDOWN WM_SYSKEYUP WM_SYSCHAR 非系统消 ...
- 高德地图开发之获取SHA1码
通过Android Studio获取SHA1 第一步.打开 Android Studio 的 Terminal 工具. 第二步.输入命令:keytool -v -list -keystore key ...
- MySQL 5.6 Reference Manual-14.5 InnoDB Tablespace Management
14.5 InnoDB Tablespace Management 14.5.1 Resizing the InnoDB System Tablespace 14.5.2 Changing the ...