Codeforces 724E Goods transportation(最小割转DP)

【题目链接】 http://codeforces.com/problemset/problem/724/E

【题目大意】

  每个城市有pi的物品可以运出去卖,si个物品可以买,
  编号小的城市可以往编号大的城市最多运送c的物品,问最多有多少物品可以被买卖

【题解】

  源点向每个城市引pi的流,每个城市向汇点引si的流,
  小编号的城市往大编号的城市引c的流,那么全图的最大流就是答案,
  但是数据量过大,我们考虑转化。
  因为最大流等于最小割,我们发现对于这个图,最后每个点不是跟s连就是跟t连,
  那么我们设dp[i][j]表示前i个城市j个城市与s连接的最小割,dp一遍即可得到答案。

【代码】

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=10010;
int n;
LL c,p[N],s[N],dp[N],ans;
int main(){
    while(~scanf("%d%lld",&n,&c)){
        for(int i=1;i<=n;i++)scanf("%lld",&p[i]);
        for(int i=1;i<=n;i++)scanf("%lld",&s[i]);
        memset(dp,0x3f,sizeof(dp));dp[0]=0;
        for(int i=1;i<=n;i++){
            for(int j=i;j;j--)dp[j]=min(dp[j]+j*c+p[i],dp[j-1]+s[i]);
            dp[0]+=p[i];
        }ans=0x3f3f3f3f3f3f3f3f;
        for(int i=0;i<=n;i++)ans=min(ans,dp[i]);
        printf("%lld\n",ans);
    }return 0;
}

  

时间: 2025-01-08 17:26:11

Codeforces 724E Goods transportation(最小割转DP)的相关文章

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 long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define PLI pair<LL, int> #define ull unsigned long lo

[codeforces724E]Goods transportation

试题描述 There are n cities located along the one-way road. Cities are numbered from 1 to n in the direction of the road. The i-th city had produced pi units of goods. No more than si units of goods can be sold in the i-th city. For each pair of cities i

Codeforces 786E. ALT 最小割+倍增

E. ALT http://codeforces.com/problemset/problem/786/E 题意: 给出一棵 n 个节点的树与 m 个工人.每个工人有一条上下班路线(简单路径),一个工人会得到满足只要下面一项满足:1.他得到一只puppy 2.他的上下班路径上每条边都有一只doge求使所有工人满足的最小dog数并输出方案.n≤20000,m≤10000 想法:暴力建图,源点连向工人Xi,边Yi连向汇点,容量为1.然后工人向其路径上的边连容量为1的边.O(nm) 优化建图:路径为树

Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

Digital collectible card games have become very popular recently. So Vova decided to try one of these. Vova has n cards in his collection. Each of these cards is characterised by its power pi, magic number ci and level li. Vova wants to build a deck

Codeforces 1009G Allowed Letters 最大流转最小割 sosdp

Allowed Letters 最直观的想法是贪心取, 然后网络流取check可不可行, 然后T了. 想到最大流可以等于最小割, 那么我们状压枚举字符代表的6个点连向汇点是否断掉, 然后再枚举64个本质不同的位置, 是否需要切段原点联想它的边, 复杂度电磁check复杂度64 * 64 用sosdp能优化到64 * 6 #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned

Codeforces 343E 最小割树

题意及思路:https://www.cnblogs.com/Yuzao/p/8494024.html 最小割树的实现参考了这篇博客:https://www.cnblogs.com/coder-Uranus/p/9771919.html 代码: #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; const int maxn = 210; const int maxm = 2010; int head[maxn

hdu 3204(最小割--关键割边)

Ikki's Story I - Road Reconstruction Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 7491   Accepted: 2172 Description Ikki is the king of a small country – Phoenix, Phoenix is so small that there is only one city that is responsible fo

漫话最小割 part1

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "PingFang SC"; color: #454545 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px "Times New Roman"; color: #2d2d2d } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Ti

UVALive 5905 Pool Construction 最小割,s-t割性质 难度:3

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3916 这道题要求一种填充+挖坑+建屏障的方法,使得这块土地上的所有坑和草地之间都有屏障,挖坑花费d每块,填充花费f每块,建屏障花费b每两块之间,注意并不要求一定有坑,但是外围一圈要一定没有坑,所以需要预先填充好 令st代表平地,ed代表坑,边权为花费,那么本题是要求一个st-