题解:

神建图

普通的二分图费用流建完后

添加学生x->t 容量为k-1的边

表示尽量让x参加一个活动,剩下的k-1次机会可以不参加

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int maxn=;
const int oo=; int n,m,k;
int a[maxn],b[maxn];
int ans=; struct Edge{
int from,to,cap,flow,cost;
};
vector<int>G[maxn];
vector<Edge>edges;
void Addedge(int x,int y,int z,int w){
Edge e;
e.from=x;e.to=y;e.cap=z;e.flow=;e.cost=w;
edges.push_back(e);
e.from=y;e.to=x;e.cap=;e.flow=;e.cost=-w;
edges.push_back(e);
int c=edges.size();
G[x].push_back(c-);
G[y].push_back(c-);
} int s,t,totn;
queue<int>q;
int inq[maxn];
int d[maxn];
int p[maxn]; int Spfa(int &nowflow,int &nowcost){
for(int i=;i<=totn;++i){
d[i]=oo;inq[i]=p[i]=;
}
d[s]=;q.push(s);
while(!q.empty()){
int x=q.front();q.pop();inq[x]=;
for(int i=;i<G[x].size();++i){
Edge e=edges[G[x][i]];
if((e.cap>e.flow)&&(d[x]+e.cost<d[e.to])){
d[e.to]=d[x]+e.cost;
p[e.to]=G[x][i];
if(!inq[e.to]){
q.push(e.to);
inq[e.to]=;
}
}
}
} if(d[t]==oo)return ;
int x=t,f=oo;
while(x!=s){
Edge e=edges[p[x]];
f=min(f,e.cap-e.flow);
x=e.from;
}
nowflow+=f;nowcost+=f*d[t];
x=t;
while(x!=s){
edges[p[x]].flow+=f;
edges[p[x]^].flow-=f;
x=edges[p[x]].from;
}
return ;
} int Mincost(){
int flow=,cost=;
while(Spfa(flow,cost)){
}
return cost;
} char ss[];
int main(){
scanf("%d%d%d",&n,&m,&k);
totn=n+m;s=++totn;t=++totn;
for(int i=;i<=m;++i)scanf("%d",&a[i]);
for(int i=;i<=m;++i)scanf("%d",&b[i]);
for(int i=;i<=m;++i){
for(int j=;j<=n;++j){
Addedge(i+n,t,,(*j-)*a[i]-b[i]);
}
}
for(int i=;i<=n;++i){
scanf("%s",ss+);
for(int j=;j<=m;++j){
if(ss[j]=='')Addedge(i,j+n,,);
}
}
for(int i=;i<=n;++i)Addedge(s,i,k,);
for(int i=;i<=n;++i)Addedge(i,t,k-,);
cout<<Mincost()<<endl;
return ;
}

BZOJ 3442 学习小组的更多相关文章

  1. 【BZOJ 3442】 3442: 学习小组 (最大费用流)

    3442: 学习小组 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 403  Solved: 193 Description [背景] 坑校准备鼓励学生 ...

  2. 【BZOJ】【3442】学习小组

    网络流/费用流 orz zyf 裸的费用流,根据题目描述即可建出如下的图: S->i 费用表示每有一个加入第 i 个小组的学生,需要花的钱,由于是跟流量(人数)的二次方相关,所以要拆边……然后每 ...

  3. bzoj3442: 学习小组(费用流好题)

    3442: 学习小组 题目:传送门 题解: 超级好题啊大佬们的神题!建图肥肠灵性!感觉自己是星际玩家... 首先呢st直接向每个人连边,容量为min(k,喜欢的小组个数),费用为0 然后每个人再向ed ...

  4. BZOJ3442: 学习小组

    Description [背景] 坑校准备鼓励学生参加学习小组. [描述]     共有n个学生,m个学习小组,每个学生有一定的喜好,只愿意参加其中的一些学习小组,但是校领导为学生考虑,规定一个学生最 ...

  5. 【刷题】洛谷 P4209 学习小组

    题目描述 共有n个学生,m个学习小组,每个学生只愿意参加其中的一些学习小组,且一个学生最多参加k个学习小组.每个学生参加学习小组财务处都收一定的手续费,不同的学习小组有不同的手续费.若有a个学生参加第 ...

  6. 怎样增加Dave 英语学习小组

    一.     增加小组 英语对IT 是非常重要的,但非常多人都不能坚持去学习,Dave 英语学习小组成立与已经超过半年,如今进行扩招.欢迎想提高英语,而且能够坚持每天学习的人,增加Dave 的小组.并 ...

  7. 【BZOJ3442】学习小组 费用流

    [BZOJ3442]学习小组 Description [背景] 坑校准备鼓励学生参加学习小组. [描述] 共有n个学生,m个学习小组,每个学生有一定的喜好,只愿意参加其中的一些学习小组,但是校领导为学 ...

  8. bzoj3442学习小组

    bzoj3442学习小组 题意: 共有n个学生,m个学习小组,每个学生只愿意参加其中的一些学习小组,且一个学生最多参加k个学习小组.每个学生参加学习小组财务处都收一定的手续费,不同的学习小组有不同的手 ...

  9. Python学习小组微信群公告页面

    <简明 Python 教程>读经群,PDF地址:https://pan.baidu.com/s/1FK8s4cTfwWxSktOfS95ArQ,PyCharm-Edu地址:https:// ...

随机推荐

  1. 使用Spring Cloud Gateway保护反应式微服务(二)

    抽丝剥茧,细说架构那些事——[优锐课] 接着上篇文章:使用Spring Cloud Gateway保护反应式微服务(一) 我们继续~ 将Spring Cloud Gateway与反应式微服务一起使用 ...

  2. DNS 访问 Service【转】

    在 Cluster 中,除了可以通过 Cluster IP 访问 Service,Kubernetes 还提供了更为方便的 DNS 访问. kubeadm 部署时会默认安装 kube-dns 组件. ...

  3. 【Winform】键 盘 事 件

    private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e) { , (, (, (, ( }; //回车 Backsp ...

  4. Java中遍历 Session 和 Request

    转: session的遍历: java.util.Enumeration e = request.getSession().getAttributeNames(); while( e.hasMoreE ...

  5. ubnutu18.4 修改交换分区大小

    ubuntu18.04默认的swap文件在根目录/下,名字是swapfile 1.查看交换分区大小  也可以使用系统监视器查看 free -m 2.创建一个swap文件 :大小为8g count= 3 ...

  6. MinGW下编译curl-7.60.0时, 发生ERROR_FILE_NOT_FOUND undeclared

    在编译curl-7.60.0时, 遇到ERROR_FILE_NOT_FOUND undeclared 这个情况, 就没法编译成功!! 下载了以往的版本, 发现是从curl-7.59.0版本开始才有 t ...

  7. 139. Word Break 以及 140.Word Break II

    139. Word Break Given a non-empty string s and a dictionary wordDict containing a list of non-empty  ...

  8. H7-TOOL脱机烧录器功能开源发布

    H7-TOOL汇总帖:https://www.cnblogs.com/armfly/p/12283459.html 当前已经对STM32F030,STM32F103,STM32F429,STM32F7 ...

  9. maven package和install

    mvn clean package依次执行了clean.resources.compile.testResources.testCompile.test.jar(打包)等7个阶段.mvn clean ...

  10. day09 Django: 组件cookie session

    day09 Django: 组件cookie session   一.cookie和session都是会话跟踪技术     1.什么是会话             可以理解为客户端和服务端之间的一次会 ...