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 ...
随机推荐
- Oracle 10G 服务端的升级
第一步:备份 rman target / backup full database plus archivelog; 第二步:升级 解压升级包到soft目录下,修改所有者 chown -R oracl ...
- 接受H0的坏处|试验误差|置信度由来|
生物统计与实验设计 置信度(0.05 0.01)是通过实验次数估计值的分布得到的,它是整个分布的期望,这个值的确立需要具体情况具体分析. 肯定很难,因为否定一次很容易.虽然如果没有否定(eg:得到p= ...
- 双股同时上市!小米IPO是想要玩场大的?
近日,据相关媒体报道,有相关人士称小米IPO最终可能敲定A+H股两地发行.但目前还未得到小米官方证实.此前关于小米要上市的消息已经流传已久了,从雷军刚开始的矢口否认到后来的默认,再到后来相关消息愈来 ...
- 在dataframe添加1行(首行,或者尾部),且不覆盖
如果直接用下面的代码添加第1行,则会覆盖掉原来的第1行. #指定位置增加一行: df.loc[0]={'a':1,'b':2} 正确方法: 新建一个同样的 dataframe, 然后合并两个dataf ...
- 常用JS代码片段
1.隐藏部分数字,如手机号码,身份证号码 1 2 3 function (str,start,length,mask_char){ return str.replace(str.substr(star ...
- 重大改革!Python将被加入高考科目!
未来大学生将分为两种:一种是编程好的人,另一种是编程超好的人. Python 将被纳入高考科目 近期,浙江省信息技术课程改革方案出台,Python 确定进入浙江省信息技术高考,从2018年起浙江省信息 ...
- 内核ioctl函数的cmd宏参数
在驱动程序里, ioctl() 函数上传送的变量 cmd 是应用程序用于区别设备驱动程序请求处理内容的值.cmd除了可区别数字外,还包含有助于处理的几种相应信息. cmd的大小为 32位,共分 4 个 ...
- YOLO 论文阅读
YOLO(You Only Look Once)是一个流行的目标检测方法,和Faster RCNN等state of the art方法比起来,主打检测速度快.截止到目前为止(2017年2月初),YO ...
- cocoapods iOS类库管理工具的安装与使用
CocoaPods是一个管理Swift和Objective-C的Cocoa项目的依赖工具.他可以优雅地帮助你扩展你的项目.简单的说,就是替你管理Swift和Objective-C的Cocoa项目的第三 ...
- lnmp 一键安装包(nginx) 运行laravel项目显示该网页无法正常运行
vi /usr/local/nginx/conf/fastcgi.conf 注释掉 PHP_ADMIN_VALUE #fastcgi_param PHP_ADMIN_VALUE "open_ ...