Beta Round #9 (酱油杯noi考后欢乐赛)最大伤害
题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFnoi%E8%80%83%E5%90%8E%E6%AC%A2%E4%B9%90%E8%B5%9B%29/%E6%9C%80%E5%A4%A7%E4%BC%A4%E5%AE%B3
题解:发现我最小割还是不怎么会T_T
而且此题题意有些不明。。。
看到出题人说就是选出一大坨,然后能加的都加。卧槽,这不是最大权闭合子图吗?
最大权闭合子图中原来有边的现在连边为inf,表示i与j必须同割,那我们连边为x,就代表i,j不同割需要扣除多少。
然后求出最小割,用总权值减去最小割,好象是对的?然后就A掉了。。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 2000+5
#define maxm 1000000
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,s,t,sum,maxflow,tot=,a[maxn],b[maxn][maxn],head[maxn],cur[maxn],h[maxn],q[maxn];
struct edge{int go,next,v;}e[maxm];
void ins(int x,int y,int z){e[++tot].go=y;e[tot].v=z;e[tot].next=head[x];head[x]=tot;}
void insert(int x,int y,int z){ins(x,y,z);ins(y,x,);}
bool bfs()
{
for(int i=s;i<=t;i++)h[i]=-;
int l=,r=;q[]=s;h[s]=;
while(l<r)
{
int x=q[++l];
for(int i=head[x];i;i=e[i].next)
if(e[i].v&&h[e[i].go]==-)
{
h[e[i].go]=h[x]+;q[++r]=e[i].go;
}
}
return h[t]!=-;
}
int dfs(int x,int f)
{
if(x==t) return f;
int tmp,used=;
for(int i=cur[x];i;i=e[i].next)
if(e[i].v&&h[e[i].go]==h[x]+)
{
tmp=dfs(e[i].go,min(e[i].v,f-used));
e[i].v-=tmp;if(e[i].v)cur[x]=i;
e[i^].v+=tmp;used+=tmp;
if(used==f)return f;
}
if(!used) h[x]=-;
return used;
}
void dinic()
{
maxflow=;
while(bfs())
{
for (int i=s;i<=t;i++)cur[i]=head[i];maxflow+=dfs(s,inf);
}
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();s=;t=n+m+;
for1(i,n+m)a[i]=read()*;
for1(i,n)for1(j,n)b[i][j]=read();
for1(i,n)for1(j,m)b[i][j+n]=b[j+n][i]=read();
for1(i,m)for1(j,m)b[i+n][j+n]=read();
for1(i,n+m)
{
int t1=,t2=;
if(a[i]>)t1+=a[i],sum+=a[i];else t2+=abs(a[i]);
for1(j,n+m)if(b[i][j])
{
t1+=b[i][j];
if(b[i][j]>)insert(i,j,b[i][j]),sum+=b[i][j];
}
if(t1)insert(s,i,t1);
if(t2)insert(i,t,t2);
}
dinic();
printf("%d\n",(sum-maxflow)/);
return ;
}
Beta Round #9 (酱油杯noi考后欢乐赛)最大伤害的更多相关文章
- Beta Round #9 (酱油杯noi考后欢乐赛)乌鸦喝水
题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...
- Beta Round #9 (酱油杯noi考后欢乐赛)随机数生成器
题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...
- Beta Round #9 (酱油杯noi考后欢乐赛)PLQ和他的小伙伴们
题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...
- Beta Round #9 (酱油杯noi考后欢乐赛)PLQ的寻宝
题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...
- 洛谷---小L和小K的NOIP考后放松赛
链接: https://www.luogu.org/contestnew/show/11805?tdsourcetag=s_pcqq_aiomsg 题解: 没人过的题我就没看 t2: 考虑每个点是朋友 ...
- Codeforces Beta Round #57 (Div. 2)
Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #52 (Div. 2)
Codeforces Beta Round #52 (Div. 2) http://codeforces.com/contest/56 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #46 (Div. 2)
Codeforces Beta Round #46 (Div. 2) http://codeforces.com/contest/49 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #31 (Div. 2, Codeforces format)
Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A #include< ...
随机推荐
- ios Toll-Free Bridging
有一些数据类型是能够在 Core Foundation Framework 和 Foundation Framework 之间交换使用的.这意味着,对于同一个数据类型,你既可以将其作为参数传入 Cor ...
- mysql分表,分区的区别和联系
一,什么是mysql分表,分区 什么是分表,从表面意思上看呢,就是把一张表分成N多个小表,具体请看mysql分表的3种方法 什么是分区,分区呢就是把一张表的数据分成N多个区块,这些区块可以在同一个磁盘 ...
- C++ Dialog Box Command IDs
#define IDOK 1 #define IDCANCEL 2 #define IDABORT 3 #define IDRETRY 4 #define IDIGNORE 5 #define IDY ...
- iOS 图片按比例压缩,指定大小压缩
使用系统方法UIImageJPEGRepresentation(UIimage *image,CGFloat quality)进行图片质量压缩,暂且叫参数quality为压缩比吧,取值范围为0-1. ...
- JavaScript学习笔记--ES6学习(四) 字符串的扩展
ES6对字符串进行了一些扩展,主要表现在对Unicode 大于\uFFFF的字符的处理上. 1. ES6中字符的Unicode表示方法 在ES5中,字符串的Unicode表示方法: \uxxxx . ...
- ES6的编码风格
编程风格 [转自http://es6.ruanyifeng.com/#docs/style] 块级作用域 字符串 解构赋值 对象 数组 函数 Map结构 Class 模块 ESLint的使用 本章探讨 ...
- 九度OJ 1076 N的阶乘 -- 大数运算
题目地址:http://ac.jobdu.com/problem.php?pid=1076 题目描述: 输入一个正整数N,输出N的阶乘. 输入: 正整数N(0<=N<=1000) 输出: ...
- 九度OJ 1468 Sharing -- 哈希
题目地址:http://ac.jobdu.com/problem.php?pid=1468 题目描述: To store English words, one method is to use lin ...
- Swift小功能点积累
label字符加删除线 let label = UILabel(frame: CGRectMake(, , , )) let attr = NSMutableAttributedString(&quo ...
- 两个由于php.ini配置错误导致的报错:ajax图片上传报错和exec报错
遇到了两个由于php.ini配置错误导致的报错:ajax图片上传报错和exec报错 首先第一个: 在做一个用ajax图片上传的功能中,php报了这样一个错误:File upload error - u ...