就是拆个点限制一下(两点一排一大片),这道题让我注意到了限制这个重要的词。我们跑网络流跑出来的图都是有一定意义的,一般这个意义就对应了问题的一种方案,一般情况下跑一个不知道对不对的方案是相对容易的我们要做的就是尽可能去限制他,使他正确,有的时候(特别是费用流)我们也要使他计算答案更加简便。

#include <cstdio>
#include <cstring>
#include <algorithm>
#define car(a) (a)
#define tech(a,b) ((a)*n+(b))
const int N=;
const int M=;
const int P=N*M;
const int E=N*N*M*;
const int Inf=0x3f3f3f3f;
struct V{
int to,next,c,f;
}c[E];
int head[P],t=;
inline void add(int x,int y,int z,int _){
c[++t].to=y,c[t].f=z,c[t].c=_,c[t].next=head[x],head[x]=t;
}
int dis[P],anc[P],S,T,n,m;
int q[P],front,back;
bool in[P];
int ans;
inline bool spfa(){
memset(dis,0x3f,sizeof(dis));
dis[S]=,in[S]=true,q[back++]=S;
if(back==P)back=;
while(front!=back){
int x=q[front++];in[x]=false;
if(front==P)front=;
for(int i=head[x];i;i=c[i].next)
if(c[i].f&&c[i].c+dis[x]<dis[c[i].to]){
dis[c[i].to]=dis[x]+c[i].c,anc[c[i].to]=i;
if(!in[c[i].to]){
q[back++]=c[i].to,in[c[i].to]=true;
if(back==P)back=;
}
}
}
return dis[T]!=Inf;
}
inline int shoot(){
int f=Inf;
for(int i=anc[T];i;i=anc[c[i^].to])f=std::min(f,c[i].f);
for(int i=anc[T];i;i=anc[c[i^].to])c[i].f-=f,c[i^].f+=f;
return f*dis[T];
}
int main(){
scanf("%d%d",&m,&n);
S=n*m+n+,T=S+;
for(int i=;i<=n;++i){
add(S,car(i),,);
add(car(i),S,,);
}
for(int i=,x;i<=n;++i)
for(int j=;j<=m;++j){
scanf("%d",&x);
for(int k=;k<=n;++k){
add(car(i),tech(j,k),,k*x);
add(tech(j,k),car(i),,-k*x);
}
add(tech(j,i),T,,);
add(T,tech(j,i),,);
}
while(spfa())ans+=shoot();
printf("%.2f",(double)ans/(double)n);
return ;
}

【BZOJ 1070】[SCOI2007]修车 费用流的更多相关文章

  1. bzoj 1070: [SCOI2007]修车 费用流

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2785  Solved: 1110[Submit][Status] ...

  2. BZOJ.1070.[SCOI2007]修车(费用流SPFA)

    题目链接 /* 神tm看错题*2.. 假如人员i依次维修W1,W2,...,Wn,那么花费的时间是 W1 + W1+W2 + W1+W2+W3... = W1*n + W2*(n-1) + ... + ...

  3. BZOJ 1070: [SCOI2007]修车 [最小费用最大流]

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 4936  Solved: 2032[Submit][Status] ...

  4. bzoj 1070 [SCOI2007]修车(最小费用最大流)

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3515  Solved: 1411[Submit][Status] ...

  5. [BZOJ1070][SCOI2007]修车 费用流

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 6209  Solved: 2641[Submit][Status] ...

  6. BZOJ 1070 拆点 费用流

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 5860  Solved: 2487[Submit][Status] ...

  7. [BZOJ 1070] [SCOI2007] 修车 【费用流】

    题目链接:BZOJ - 1070 题目分析 首先想到拆点,把每个技术人员拆成 n 个点,从某个技术人员拆出的第 i 个点,向某辆车连边,表示这是这个技术人员修的倒数第 i 辆车.那么这一次修车对整个答 ...

  8. 【BZOJ1070】[SCOI2007]修车 费用流

    [BZOJ1070][SCOI2007]修车 Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的. ...

  9. bzoj 1070 [SCOI2007]修车——网络流(拆边)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1070 后面还有几辆车在这个人这儿修,自己这辆车的时间对总时间的贡献就要多乘上几倍. 所以可以 ...

随机推荐

  1. latex01-LaTeX环境的安装与配置

    以Tex Live (跨平台的发行版软件)为例. 1.官网下载iso镜像文件 2.用advanced.bat 安装(管理员权限) 选择要安装的包(主要是去掉多余的语言包) 测试Tex Live 是否正 ...

  2. Leecode刷题之旅-C语言/python-28.实现strstr()

    /* * @lc app=leetcode.cn id=28 lang=c * * [28] 实现strStr() * * https://leetcode-cn.com/problems/imple ...

  3. 工作中使用的linux命令汇总

    ln -s  /usr/local/tomcat/ ./tomcat   创建软连接到/usr/local/tomcat tar -zxvf apache-kylin-2.4.0-bin-hbase1 ...

  4. mybatis 打印SQL

    如果使用的是application.properties文件,加入如下配置: #打印SQL logging.level.com.jn.ssr.supererscuereporting.dao=debu ...

  5. C++11中std::move的使用

    std::move is used to indicate that an object t may be "moved from", i.e. allowing the effi ...

  6. Python字符串处理:过滤字符串中的英文与符号,保留汉字

    使用Python 的re模块,re模块提供了re.sub用于替换字符串中的匹配项. re.sub(pattern, repl, string, count=0) 参数说明: pattern:正则重的模 ...

  7. springmvc+spring-data-jpa+hibernate环境搭建与配置

    1.JPA诞生的缘由是为了整合第三方ORM框架,建立一种标准的方式,百度百科说是JDK为了实现ORM的天下归一,目前也是在按照这个方向发展,但是还没能完全实现.在ORM框架中,Hibernate是一支 ...

  8. 签名的html

    <b><a href="http://www.feiyuanxing.com" style="color:red">未来星开发团队--狒 ...

  9. ABP框架插件开发

    http://personball.com/abp/2017/08/21/abp-how-to-use-plugin

  10. nodejs的交叉(跨平台)编译(to android)

    nodejs的二进制包有两种安装方式node-gyp以及node-pre-gyp 这两条命令会写入该包的安装脚本. node-gyp是使用gyp工具编译源码,因此必须指定交叉编译器(参见http:// ...