2016 Multi-University Training Contest 4 T9
http://acm.hdu.edu.cn/showproblem.php?pid=5772
最大权闭合子图。
得到价值w[i][j]的条件是选了i,j这两个位置的字符。选择位置的i字符花费为
第一次选s[i]:a[s[i]] 不是第一次选s[i]:b[s[i]]
所以对于选i位置字符前提为选了花费为b[s[i]]-a[s[i]]的字符i。
得到上面的关系图后然后就是普通的最大权闭合子图问题,直接求解即可。
#include<cstdio>
#include<cstring>
#define M 120010
#define N 6010
#define inf 1000000000
int len[M <<],e[M <<],nex[M <<],other[M <<],head[N],last[N],d[N],num[N];
int te,sum,_,j,num1,num2,w[][],a[],b[],m,n,i,ans,tot,ss,tt,ee,u,v,c;
char s[];
int init()
{
memset(head,,sizeof(head));
memset(num,,sizeof(num));
memset(d,,sizeof(d));
ans=ee=;
}
int min(int a,int b)
{
return a<b?a:b;
}
void add(int u,int v,int c)
{
//printf("%d %d %d\n",u,v,c);
other[++ee]=ee+;
e[ee]=v;nex[ee]=head[u];head[u]=ee;len[ee]=c;
other[++ee]=ee-;
e[ee]=u;nex[ee]=head[v];head[v]=ee;len[ee]=;
}
int dfs(int x,int flow)
{
int rec,j,p;
if (x==tt) return flow;
rec=;j=last[x];
while (j!=)
{
if (len[j]> && d[x]==d[e[j]]+)
{
last[x]=j;
p=dfs(e[j],min(len[j],flow-rec));
len[j]-=p;len[other[j]]+=p;
rec+=p;
if (rec==flow) return rec;
}
j=nex[j];
}
if (d[ss]>tot) return rec;
if (--num[d[x]]==) d[ss]=tot;
last[x]=head[x];
num[++d[x]]++;
return rec;
}
int main()
{
scanf("%d",&_);
while (_--)
{
sum=;init();
scanf("%d",&n);
scanf("%s",s+);
for (i=;i<=;i++)
scanf("%d%d",&a[i],&b[i]);
for (i=;i<=n;i++)
for (j=;j<=n;j++)
scanf("%d",&w[i][j]);
num1=;ss=;
for (i=;i<=n;i++)
for (j=i+;j<=n;j++)
if (w[i][j]+w[j][i]!=)
{
add(ss,++num1,w[i][j]+w[j][i]);
sum+=w[i][j]+w[j][i];
}
num2=;tt=num1+n+;
for (i=;i<=n;i++)
for (j=i+;j<=n;j++)
if (w[i][j]+w[j][i]!=)
{
add(++num2,num1+i,inf);
add(num2,num1+j,inf);
}
for (i=;i<=n;i++)
{
add(num1+i,num1+n+s[i]-''+,inf);
add(num1+i,tt,a[s[i]-'']);
}
for (i=;i<=;i++)
add(num1+n+i+,tt,b[i]-a[i]);
tot=num[]=tt;
for (i=ss;i<=tt;i++)
last[i]=head[i];
while (d[ss]<tot)
ans+=dfs(ss,);
printf("Case #%d: %d\n",++te,sum-ans);
}
return ; }
| Run ID | Submit Time | Judge Status | Pro.ID | Exe.Time | Exe.Memory | Code Len. | Language | Author |
| 17819971 | 2016-07-29 15:40:45 | Accepted | 5772 | 15MS | 2052K | 2416 B | G++ | lbz007 |
2016 Multi-University Training Contest 4 T9的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 2016 Al-Baath University Training Camp Contest-1 E
Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 2016 Al-Baath University Training Camp Contest-1 J
Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...
- 2016 Al-Baath University Training Camp Contest-1 I
Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...
- 2016 Al-Baath University Training Camp Contest-1 H
Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...
- 2016 Al-Baath University Training Camp Contest-1 G
Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...
- 2016 Al-Baath University Training Camp Contest-1 F
Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...
- 2016 Al-Baath University Training Camp Contest-1 D
Description X is well known artist, no one knows the secrete behind the beautiful paintings of X exc ...
随机推荐
- Android开发之《安全防护》
逆向 java混淆 so加固 网络传输安全
- tfjs-node初体验:训练模型的存储
JS,一门从浏览器兴起,却不止于浏览器的脚本,个人一直认为其是最有潜力的脚本语言.不只是因为ES6优雅的语法,更重要的是其易上手,跨平台的优点. Node将JS从browser带去了client是革命 ...
- JavaScript中对象数组去重方法
在一次对后端返回的对象数组的操作时想通过indexOf()或者includes()的方法来实现对对象数组的去重但是行不通,因为用indexOf()返回的都是-1,一下记录两种对象数组(更具指定属性)去 ...
- POJ 2112 Optimal Milking 最短路 二分构图 网络流
题意:有C头奶牛,K个挤奶站,每个挤奶器最多服务M头奶牛,奶牛和奶牛.奶牛和挤奶站.挤奶站和挤奶站之间都存在一定的距离.现在问满足所有的奶牛都能够被挤奶器服务到的情况下,行走距离的最远的奶牛的至少要走 ...
- Python 学习之Anaconda 设置默认打开chrome 浏览器
笔者遇到的问题如何设置jupyter notebook 打开chrome 浏览器 1.打开anaconda prompt 2.输入jupyter notebook --generate-config ...
- MySQL5.7主从复制slave报Last_Errno: 1146错误解决
前提:由于slave磁盘未及时扩容原因导致磁盘即将写满,为了不影响业务将slave实例里一个10G的库drop了(项目前期建的库,数据现在已不使用了),然后又drop了master上的该库(对于大库建 ...
- centos7上Jenkins通过rpm包方式直接安装及使用war包方式升级
一.通过rpm包方式直接安装jenkins 1.官网下载rpm安装包(前提是安装jdk) wget https://pkg.jenkins.io/redhat-stable/jenkins-2.121 ...
- 手把手教你利用Jenkins持续集成iOS项目
前言 众所周知,现在App的竞争已经到了用户体验为王,质量为上的白热化阶段.用户们都是很挑剔的.如果一个公司的推广团队好不容易砸了重金推广了一个APP,好不容易有了一些用户,由于一次线上的bug导致一 ...
- 对话|人工智能先驱Yoshua Bengio
Bengio"> 今年1月份,微软收购深度学习初创公司Maluuba时,Maluuba公司德高望重的顾问.深度学习先驱Yoshua Bengio也接手了微软的人工智能研究顾问 ...
- 这有一管信息量很大的DNA
题图:华盛顿大学副教授Luis Henrique Ceze(照片中的男士)和研究科学家Lee Organick正将数字数据保存进DNA测序,以供"读取"并追溯原始文件. 来自微软和 ...