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

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

#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. MySQL 5.7.10 免安装配置

    # 配置环境:windows 64bit # 安装版本:mysql-5.7.10-win32(zip archive版本) 1. ZIP Archive版是免安装的,只需把mysql-5.7.10-w ...

  2. Java面试题之五

    二十一.super()与this()的区别? (1)用this的情况: 1.在构造方法中,通过this调用另一个构造方法,用法:this(参数列表). 2.在函数参数或函数的局部变量与成员变量同名,即 ...

  3. 新辰:4G时代怎样利用手机进行移动APP营销?

    未来的时代是4G时代,新辰手机用户的搜索量不在电脑端之下.那么,我们要怎样用手机进行营销呢?手机站点的竞价文章,要怎样去写比較好?手机站点要做专题吗?手机站点的优化思路在哪里?手机的系统不同,在不同的 ...

  4. 从Excel转Access的一个方法说开去(DataRow的state状态)

    因为客户对access不太熟悉,更喜欢玩EXCEL.但是系统要求导入ACCESS.所以我们得做个把EXCEL转换成Access的小工具.(别问我为啥不让系统直接导入excel....我不知道!),然后 ...

  5. HTML系列(八):表格

    一.基本表格: 表格标记<table>,行标记<tr>,单元格标记<td> 基本语法: <table> <tr> <td>单元格 ...

  6. ue中替换行

    把替换的字符替换为^p 如:123,12,3,1, 在UE力把“,”替换未“^p”,就会替换为 1231231

  7. PL/SQL database character set(AL32UTF8) and Client character set(ZHS16GBK) are different

    启动PL/SQL Developer 报字符编码不一致错误 Database character set (AL32UTF8) and Client character set (ZHS16GBK) ...

  8. [问题解决] File "/struts-tags" not found

    错误:org.apache.jasper.JasperException: File "/struts-tags" not found 发生场景:tomcat服务器 解决方案:将t ...

  9. VC++中的类的内存分布(上)(通过强制转换,观察地址,以及地址里的值来判断)

    0.序 目前正在学习C++中,对于C++的类及其类的实现原理也挺感兴趣.于是打算通过观察类在内存中的分布更好地理解类的实现.因为其实类的分布是由编译器决定的,而本次试验使用的编译器为VS2015 RC ...

  10. HDU 2167 Pebbles

    题目大意:有个N*N( 3<=N<=15 )方阵, 可从中若干个数, 使其总和最大.取数要求, 当某一个数被选, 其周围8个数都不能选. 题解:记s数组为合法状态,即没有相邻的数字同时被选 ...