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 ...
随机推荐
- labview学习——生产者/消费者(数据)(事件)
其主要的模型: 主要从以下几个方面理解: 1.可重入性 正常的labview是多线程设计语言,而我们在执行VI时的规则是通过VI的命名来分别调用实现的. 打开VI的Highlight调试工具,可以看出 ...
- 忘记mysql密码后重置密码
https://jingyan.baidu.com/album/c275f6ba479ca9e33d7567ee.html?picindex=4 找不到mysql的my.ini文件问题: https: ...
- 用artifactory搭建maven2内部服务器
访问http://www.jfrog.org/sites/jfrog/index.html 下载最新的zip包(内置jetty) 下载和解压artifactory.目录结构如下: 这些目录是: bac ...
- mac 下openOffice服务的安装
1.安装准备 安装 Homebrew 及 Homebrew-Cask Homebrew 是一个Mac上的包管理工具.使用Homebrew可以很轻松的安装缺少的依赖. Homebrew-Cask是建立在 ...
- NBA球星的生意经 个人流量化之路
个人流量化之路" title="NBA球星的生意经 个人流量化之路"> 在国人欢天喜地的庆祝新春佳节之时,大洋彼岸也在进行着让全球篮球迷为之"着魔&quo ...
- 为啥java要使用 set ()和get()方法---封装
封装性:属性封装,方法封装,类封装,组件封装等 例如:如果属性没有封装,那么在本类对象之外创建对象后,可以直接访问属性 private关键字,只能在本类中访问,想要在外部访问私有属性,我们需要提供公有 ...
- rpm报错warning: /var/tmp/rpm-tmp.1OZa8q: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY的解决
参考链接:http://blog.51cto.com/zymin0823/1546537 报错: 解决:使用如下两个选项
- redis命令学习(二) · THIS SPACE
列表(Lists)操作命令 Redis列表是简单的字符串列表,按照插入顺序排序. 你可以添加一个元素导列表的头部(左边)或者尾部(右边)LPUSH命令插入一个新的元素导头部,而RPUSH插入一个新元素 ...
- 玩转UITableView
UITableView这个iOS开发中永远绕不开的UIView,那么就不可避免的要在多个页面多种场景下反复摩擦UITableView,就算是刚跳进火坑不久的iOS Developer也知道实现UITa ...
- spring cloud实战 1-高可用注册中心
创建父maven项目 提交代码至GitHub 创建eureka-server-1 项目搭建两种方式: 父pom中继承spring-boot-starter-parent,子pom中直接结成父pom.该 ...