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. 02慕课网《进击Node.js基础(一)》——CommonJs标准

    是一套规范管理模块 每个js 为一个模块,多个模块作为一个包 node.js和Couchdb是对其的实现: 不同于jQuery 模块:定义.标识.引用(地址/模块名称) 模块类型: 核心模块http ...

  2. 【Leetcode】 328. Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  3. ant 安装及基础教程 !

    这篇文章主要介绍了ant使用指南详细入门教程,本文详细的讲解了安装.验证安装.使用方法.使用实例.ant命令等内容,需要的朋友可以参考下   一.概述 ant 是一个将软件编译.测试.部署等步骤联系在 ...

  4. jetty之maven配置

    <!-- jetty 插件配置 --><plugin> <groupId>org.mortbay.jetty</groupId> <artifac ...

  5. BZOJ4890 Tjoi2017城市

    显然删掉的边肯定是直径上的边.考虑枚举删哪一条.然后考虑怎么连.显然新边应该满足其两端点在各自树中作为根能使树深度最小.只要线性求出这个东西就可以了,这与求树的重心的过程类似. #include< ...

  6. Codeforces Round#514 Div.2 翻车记

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  7. [TJOI2013]单词 AC自动机

    题面: 洛谷 题解: 很久之前做的题了,只不过之前一直90....最近才发现是哪里写错了. 我们对字符集建AC自动机. 首先考虑一个暴力的做法,把文章当做一个长串,直接在自动机上跳,但是我们会发现,这 ...

  8. Combining HTML5 Web Applications with OpenCV

    The Web Dev Zone is brought to you by Stormpath—offering a pre-built Identity API for developers. Ea ...

  9. Splitter Control for Dialog

    原文链接地址:https://www.codeproject.com/Articles/595602/Splitter-Control-for-Dialog Introduction Yes, tha ...

  10. msiexec安装参数详解

    原文链接地址:https://blog.csdn.net/wilson_guo/article/details/8151632 1 安装 /i表示安装,/x 表示卸载/f表示修复./l*v 表示输出详 ...