[arc078f]Mole and Abandoned Mine
来源:互联网 发布:java 异或运算符 编辑:程序博客网 时间:2024/06/06 09:42
题目大意
一张无向带权连通图,删去边权和尽量小的边使得1->n路径唯一。
DP
设f[s,i]表示1->i,目前和1联通的集合是s,1->i不存在两条路,能保留的最大边权和。
转移分两种,一种是加一条桥,一种是给i挂一个集合。
即
还有
p[y]表示一个集合保留内部所有边权和。
#include<cstdio>#include<algorithm>#define fo(i,a,b) for(i=a;i<=b;i++)#define two(i) (1<<(i-1))using namespace std;const int maxn=15+10,inf=1000000000;int f[(1<<16)+10][maxn],p[(1<<16)+10],id[(1<<16)+10];int dis[maxn][maxn];int i,j,k,l,r,s,t,n,m,now,all,ans,sum;int lowbit(int x){ return x&-x;}int main(){ scanf("%d%d",&n,&m); fo(i,1,n) id[two(i)]=i; all=(1<<n)-1; fo(i,1,m){ scanf("%d%d%d",&j,&k,&t); sum+=t; dis[j][k]=dis[k][j]=t; } fo(i,1,all){ now=id[lowbit(i)]; p[i]=p[i-two(now)]; fo(j,now+1,n) if ((i&two(j))) p[i]+=dis[now][j]; } fo(i,0,n) fo(j,0,all) f[j][i]=-inf; f[two(1)][1]=0; ans=-inf; fo(s,1,all){ fo(i,1,n){ r=s; while (r){ if ((r&two(i))) f[s][i]=max(f[s][i],f[(s-r)|two(i)][i]+p[r]); r=(r-1)&s; } fo(j,1,n) if (!(s&two(j))&&dis[i][j]) f[s|two(j)][j]=max(f[s|two(j)][j],f[s][i]+dis[i][j]); } if ((s&two(n))) ans=max(ans,f[s][n]); } printf("%d\n",sum-ans);}
阅读全文
0 0
- [arc078f]Mole and Abandoned Mine
- ARC 078F Mole and Abandoned Mine 状压DP
- mole
- mole
- Abandoned object and Removed object 区分
- CHAPTER ONE - CHILDHOOD - Abandoned and Chosen
- MINE
- MINE
- mine
- Mine
- A. Little Pony and Crystal Mine
- A. Little Pony and Crystal Mine
- Maze&&Mole
- christian louboutin paris "Criminal Law" also provides the indecent assault of women and child mole
- An old post of mine for Leo and all newbies
- Codeforces 454A. Little Pony and Crystal Mine
- Codeforces Div. 2 #259-A. Little Pony and Crystal Mine
- CF 454A(Little Pony and Crystal Mine-画图[水])
- iframe的应用场景
- 测试基本流程2
- 线段树(区间修改,单点查询)
- OOP思想
- 在centos7服务器上安装anaconda和jupyter notebook
- [arc078f]Mole and Abandoned Mine
- 二叉树的前序,中序,后序遍历Java实现
- retrofit简单的get请求
- spring boot 1.5.7 搭建基础项目框架二 错误: 找不到或无法加载主类
- CSS3去除点input、button击后的出现的边框
- 移植u-boot-2012.04----支持NORFlash启动
- WPF中Brush的派生类,实例发光的小球
- mybatis中动态sql常用的标签
- MySql数据库面试