首页 技术 正文
技术 2022年11月15日
0 收藏 632 点赞 3,839 浏览 1438 个字

(2016北京集训十四)【xsy1557】task

题解:

限制可以看成图状结构,每个任务的对物品数量的影响可以看成权值,只不过这个权值用一个五元组来表示。

那么题意要求的就是最大权闭合子图,网络流经典应用。

代码:

 #include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define inf 100000000000000000
using namespace std;
typedef long long ll;
struct edge{
int v,next;
ll w;
}a[];
int n,m,k,u,v,vs,vt,tot=,dep[],anss[],head[];
ll ans=,tmp,sum=,cnt=;
char op[];
queue<int>q;
void add(int u,int v,ll w){
a[++tot].v=v;
a[tot].w=w;
a[tot].next=head[u];
head[u]=tot;
}
bool bfs(){
memset(dep,,sizeof(dep));
while(!q.empty())q.pop();
q.push(vs);
dep[vs]=;
while(!q.empty()){
int u=q.front();
q.pop();
for(int tmp=head[u];tmp!=-;tmp=a[tmp].next){
int v=a[tmp].v;
if(!dep[v]&&a[tmp].w){
dep[v]=dep[u]+;
if(v==vt)return true;
q.push(v);
}
}
}
return false;
}
ll dfs(int u,ll num){
if(u==vt||!num)return num;
ll ans=;
for(int tmp=head[u];tmp!=-;tmp=a[tmp].next){
int v=a[tmp].v;
ll w=a[tmp].w;
if(dep[v]==dep[u]+&&w){
ll f=dfs(v,min(num,w));
if(f){
a[tmp].w-=f;
a[tmp^].w+=f;
ans+=f;
num-=f;
if(!num)break;
}
}
}
if(num>)dep[u]=-;
return ans;
}
int main(){
memset(head,-,sizeof(head));
scanf("%d%d%d",&n,&m,&k);
vs=n+,vt=n+;
for(int i=;i<=k;i++)ans=ans*+;
for(int i=;i<=n;i++){
scanf("%s",op+);
tmp=;
for(int j=;j<=k;j++){
tmp*=;
if(op[j]=='+')tmp++;
if(op[j]=='-')tmp--;
}
if(tmp<){
add(vs,i,-tmp);
add(i,vs,);
}else{
sum+=tmp;
add(i,vt,tmp);
add(vt,i,);
}
}
for(int i=;i<=m;i++){
scanf("%d%d",&u,&v);
add(v,u,inf);
add(u,v,);
}
while(bfs()){
cnt+=dfs(vs,inf);
}
ans-=cnt-sum;
for(int i=k;i;i--){
anss[i]=ans%;
ans/=;
}
for(int i=;i<=k;i++)printf("%d ",anss[i]);
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,946
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,472
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,285
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,101
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,733
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,768