先考虑假如全部输了的收益. 再考虑每场比赛球队赢了所得收益的增加量,用这个来建图..

--------------------------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
#define Rep( i , n ) for( int i = 1 ; i <= n ; ++i )
 
using namespace std;
 
const int maxn = 6000 + 5;
const int INF = 0x3f3f3f3f;
 
struct edge {
int to , cap , cost;
edge *next , *rev;
};
 
edge* pt;
edge* head[ maxn ];
edge EDGE[ 20000 ];
 
void init() { 
pt = EDGE;
clr( head , 0 );
}
 
inline void add( int u , int v , int d , int w ) {
pt -> to = v;
pt -> cap = d;
pt -> cost = w;
pt ->next = head[ u ];
head[ u ] = pt++;
}
 
inline void add_edge( int u , int v , int d , int w ) {
add( u , v , d , w );
add( v , u , 0 , -w );
head[ u ] -> rev = head[ v ];
head[ v ] -> rev = head[ u ];
}
 
edge* p[ maxn ];
int d[ maxn ] , a[ maxn ] , inQ[ maxn ];
 
int min_cost( int S , int T ) {
int cost = 0;
for( ; ; ) {
clr( d , INF );
d[ S ] = 0;
clr( inQ , 0 );
queue< int > Q;
a[ S ] = INF , Q.push( S );
while( ! Q.empty() ) {
int x = Q.front();
Q.pop();
inQ[ x ] = false;
   for( edge* e = head[ x ] ; e ; e =  e -> next )
       if( e -> cap > 0 && d[ e -> to ] > d[ x ] + e -> cost ) {
       
        int to = e -> to;
       
        d[ to ] = d[ x ] + e -> cost;
        a[ to ] = min( a[ x ] , e -> cap );
        p[ to ] = e;
       
        if( ! inQ[ to ] ) 
           Q.push( to ) , inQ[ to ] = true;
           
       }
       
}
if( d [ T ] == INF ) break;
cost += d[ T ] * a[ T ];
int x = T;
while( x != S ) {
p[ x ] -> cap -= a[ T ];
p[ x ] -> rev -> cap += a[ T ];
x = p[ x ] -> rev -> to;
}
}
return cost; 
}
 
int win[ maxn ] , lose[ maxn ];
int C[ maxn ] , D[ maxn ];
int cnt[ maxn ];
 
int main() {
init();
int n , m;
cin >> n >> m;
int s = 0 , t = n + m + 1;
Rep( i , n ) {
   scanf( "%d%d%d%d" , &win[ i ] , &lose[ i ] , &C[ i ] , &D[ i ] );
   cnt[ i ] = 0;
}
Rep( i , m ) {
int u , v;
scanf( "%d%d" , &u , &v );
cnt[ u ]++ , cnt[ v ]++;
add_edge( s , i , 1 , 0 );
add_edge( i , u + m , 1 , 0 );
add_edge( i , v + m , 1 , 0 );
}
int ans = 0;
Rep( i , n ) {
int x = i + m;
lose[ i ] += cnt[ i ];
ans += C[ i ] * win[ i ] * win[ i ] + D[ i ] * lose[ i ] * lose[ i ];
while( cnt[ i ]-- ) {
add_edge( x , t , 1 , 2 * ( C[ i ] * win[ i ] - D[ i ] * lose[ i ] ) + C[ i ] + D[ i ] );
win[ i ]++;
lose[ i ]--;
}
}
cout << min_cost( s , t ) + ans << "\n";
return 0;
}

--------------------------------------------------------------------------------------------------

1449: [JSOI2009]球队收益

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 500  Solved: 272
[Submit][Status][Discuss]

Description

Input

Output

一个整数表示联盟里所有球队收益之和的最小值。

Sample Input

3 3
1 0 2 1
1 1 10 1
0 1 3 3
1 2
2 3
3 1

Sample Output

43

HINT

Source

BZOJ 1449: [JSOI2009]球队收益( 最小费用最大流)的更多相关文章

  1. BZOJ 1449: [JSOI2009]球队收益 最小费用最大流 网络流

    https://www.lydsy.com/JudgeOnline/problem.php?id=1449 给每条路加上一个权值,每条路的费用是这条路的流量*权值,求最大流的最小费用. 每次spfa记 ...

  2. bzoj 1449 [JSOI2009]球队收益(费用拆分,最小费用流)

    1449: [JSOI2009]球队收益 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 547  Solved: 302[Submit][Status][ ...

  3. BZOJ 1449 JSOI2009 球队收益 费用流

    题目大意:给定nn支球队.第ii支球队已经赢了winiwin_i场.输了loseilose_i场,接下来还有mm场比赛.每一个球队终于的收益为Ci∗x2i+Di∗y2iC_i*x_i^2+D_i*y_ ...

  4. 【BZOJ 1449】 1449: [JSOI2009]球队收益 (最小费用流)

    1449: [JSOI2009]球队收益 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 841  Solved: 483 Description Inpu ...

  5. 【BZOJ-1449&2895】球队收益&球队预算 最小费用最大流

    1449: [JSOI2009]球队收益 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 648  Solved: 364[Submit][Status][ ...

  6. 1449: [JSOI2009]球队收益

    1449: [JSOI2009]球队收益 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 757  Solved: 437[Submit][Status][ ...

  7. BZOJ1449[JSOI2009]球队收益&BZOJ2895球队预算——最小费用最大流

    题目描述 输入 输出 一个整数表示联盟里所有球队收益之和的最小值. 样例输入 3 3 1 0 2 1 1 1 10 1 0 1 3 3 1 2 2 3 3 1 样例输出 43 提示   要求总费用最低 ...

  8. BZOJ 2668 [cqoi2012]交换棋子 | 最小费用最大流

    传送门 BZOJ 2668 题解 同时分别限制流入和流出次数,所以把一个点拆成三个:入点in(x).中间点mi(x).出点ou(x). 如果一个格子x在初始状态是黑点,则连(S, mi(x), 1, ...

  9. BZOJ 1061 志愿者招募(最小费用最大流)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1061 题意:申奥成功后,布布经过不懈努力,终于 成为奥组委下属公司人力资源部门的主管.布 ...

随机推荐

  1. windows 7 memcached报failed to install service or service already installed的解决方案

    今天心血来潮捣鼓一下memcache,由于系统是windows 7,我参考了 Windows下安装Memcache 使用memcached for Win32. 在运行memcached.exe -d ...

  2. ADO.NET FOR MySQL帮助类

    using System; using System.Collections; using System.Collections.Specialized; using System.Data; usi ...

  3. HTML5中video的使用一

    <!DOCTYPE html> <html> <head> <title>HTML5 </title> <meta http-equi ...

  4. HTML5的绘图的支持

    一.简单介绍canvas元素 <canvas.../>是HTML5新增的一个元素,该元素用于绘制图形.实际上<canvas../>只是相当于一张画布. 它除了可以指定通用属性外 ...

  5. English - 英语学习小笔记

    1.It is...to do sth:做某事是.... 解析:It 是形式主语,后面一半接形容词做表语,to do sth是不定式短语作真正主语. 2.make do和make doing是两种表达 ...

  6. 关于K-Means算法

    在数据挖掘中,K-Means算法是一种cluster analysis的算法,其主要是来计算数据聚集的算法,主要通过不断地取离种子点最近均值的算法. 问题 K-Means算法主要解决的问题如下图所示. ...

  7. 选择器,$("A+B") 和$("A~B") 的理解

    在我发表这个理解之前,我有看过博客园 永恒浪子 大神的 JQuery选择器大全(http://www.cnblogs.com/hulang/archive/2011/01/12/1933771.htm ...

  8. 浅谈Qt事件的路由机制:鼠标事件

    请注意,本文是探讨文章而不是教程,是根据实验和分析得出的结果,可能是错的,因此欢迎别人来探讨和纠正. 这几天对于Qt的事件较为好奇,平时并不怎么常用,一般都是用信号,对于事件的处理,一般都是需要响应键 ...

  9. BZOJ 3533: [Sdoi2014]向量集( 线段树 + 三分 )

    答案一定是在凸壳上的(y>0上凸壳, y<0下凸壳). 线段树维护, 至多N次询问, 每次询问影响O(logN)数量级的线段树结点, 每个结点O(logN)暴力建凸壳, 然后O(logN) ...

  10. linux杂记(七)linux档案与目录管理指令

    1.目录的相关操作:cd,pwd,mkdir,rmdir 路径(PATH): 绝对路径:路径的写法[一定由根目录/写起],例如/usr/share/doc这个目录 相对路径:路径的写法[不是由/写起] ...