http://codeforces.com/contest/724/problem/E

题目大意:有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i<j,可以从城市i往j运输最多c件商品。 求最多一共能卖出多少件商品。  n<=10000

思路:

定义dp(i,j)目前在位置i,删除了j个s(换说法就是:dp[i,j]表示前i个中有j个和源点相通的最小割)
转移:如果第i个点不和源点相连,那么pi这条边一定要割掉,并且之前和源点相连的j个点,每个点会有一条边连向第i个点,这些边也要割掉。
花费是dp[i-1][j]+p[i]+j*c;
如果第i个点和源点相连,那么si这条边肯定要割掉。 花费是dp[i-1][j-1]+s[i];
故dp[i][j]=min(dp[i-1][j]+p[i]+j*c,dp[i-1][j-1]+s[i])。

刚开始智障的定义错了,估计网络流写多了习惯性的拆点了

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = + ;
const LL inf = 1e18;
LL dp[][maxn];
LL p[maxn], s[maxn];
int n, c;
/*
定义dp(i, j)表示目前是第i个position,我们要删除j个p
如果这次删除的是s
dp(i, j) = min(dp(i, j), dp(i-1, j) + (i-j) * c + s[i]);
如果是删除p
dp(i, j+1) = min(dp(i, j+1), dp(i-1, j) + p[i])
///抱歉。上面的方法是错误的TAT。网络流做多了都一直习惯的把节点分开了 定义dp(i,j)目前在位置i,删除了j个s(换说法就是:dp[i,j]表示前i个中有j个和源点相通的最小割)
转移:如果第i个点不和源点相连,那么pi这条边一定要割掉,并且之前和源点相连的j个点,每个点会有一条边连向第i个点,这些边也要割掉。
花费是dp[i-1][j]+p[i]+j*c;
如果第i个点和源点相连,那么si这条边肯定要割掉。 花费是dp[i-1][j-1]+s[i];
故dp[i][j]=min(dp[i-1][j]+p[i]+j*c,dp[i-1][j-1]+s[i])。
*/ int main(){
cin >> n >> c;
for (int i = ; i <= n; i++)
scanf("%lld", p + i);
for (int i = ; i <= n; i++)
scanf("%lld", s + i);
int pos = ;
for (int i = ; i <= n; i++){
pos = pos ^ ;
for (int j = ; j <= i; j++) dp[pos][j] = inf;
for (int j = ; j < i; j++){
dp[pos][j + ] = min(dp[pos][j + ], dp[pos ^ ][j] + s[i]);
dp[pos][j] = min(dp[pos][j], dp[pos ^ ][j] + 1LL * j * c + p[i]);
}
}
LL ans = inf;
for (int i = ; i <= n; i++) ans = min(dp[pos][i], ans);
cout << ans << endl;
return ;
}

最小割dp Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E的更多相关文章

  1. CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort    暴力枚举,水 1.题意:n*m的数组, ...

  2. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E - Goods transportation 最大流转最小割转dp

    E - Goods transportation 思路:这个最大流-> 最小割->dp好巧妙哦. #include<bits/stdc++.h> #define LL long ...

  3. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)

    题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...

  4. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation 动态规划

    E. Goods transportation 题目连接: http://codeforces.com/contest/724/problem/E Description There are n ci ...

  5. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) F - Uniformly Branched Trees 无根树->有根树+dp

    F - Uniformly Branched Trees #include<bits/stdc++.h> #define LL long long #define fi first #de ...

  6. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence

    传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...

  7. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing

    我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...

  8. 贪心+树状数组维护一下 Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) D

    http://codeforces.com/contest/724/problem/D 题目大意:给你一个串,从串中挑选字符,挑选是有条件的,按照这个条件所挑选出来的字符集合sort一定是最后选择当中 ...

  9. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) D. Dense Subsequence 暴力

    D. Dense Subsequence 题目连接: http://codeforces.com/contest/724/problem/D Description You are given a s ...

随机推荐

  1. 软工实践-Alpha 冲刺 (8/10)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 已经解决登录注册等基本功能的界面. 完成非功能的主界面制作 ...

  2. HDU 5666 Segment 数论+大数

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  3. lintcode-418-整数转罗马数字

    418-整数转罗马数字 给定一个整数,将其转换成罗马数字. 返回的结果要求在1-3999的范围内. 说明 什么是 罗马数字? https://en.wikipedia.org/wiki/Roman_n ...

  4. 使用ssh公钥登陆

    记录一下使用的具体命令,具体参考: Centos设置禁止密码登录而只使用密钥登录SSH方法  优先参考这个. ssh使用公钥授权不通过的问题解决 Xshell配置ssh免密码登录-密钥公钥(Publi ...

  5. WPF和Expression Blend开发实例:模拟QQ登陆界面打开和关闭特效

    不管在消费者的心中腾讯是一个怎么样的模仿者抄袭者的形象,但是腾讯在软件交互上的设计一直是一流的.正如某位已故的知名产品经理所说的:设计并非外观怎样,感觉如何.设计的是产品的工作原理.我觉得腾讯掌握了其 ...

  6. PAT 甲级 1019 General Palindromic Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...

  7. Linux输入子系统:多点触控协议 -- multi-touch-protocol.txt768

    转自:http://blog.csdn.net/droidphone/article/details/8434768 Multi-touch (MT) Protocol --------------- ...

  8. Hibernate 中 load() 和 get() 的区别

    get 和 load 方式都是是根据 id 取得一个记录.下边详细说一下 get 和 load 的不同,因为有些时候为了对比也会把 find 加进来. 1.从返回结果上对比: load 方式检索不到的 ...

  9. dom对象转成jquery对象时候 变成数组 jquery转成dom时候 取数组第一个

  10. Django获取多个数据及文件上传

    1. 选择性别: 1)更新login.html模板 2)views.py中获取客户端提交的数据 3)当选择性别为“男”后,后台得到了gender=1. 2.选择爱好,可以多选,所以后台会获得多个数据. ...