HDU3996 Gold Mine最大权闭合图 2011 Multi-University Training Contest 16 - Host by TJU
来源:互联网 发布:苹果越狱软件源 编辑:程序博客网 时间:2024/06/05 03:55
Gold Mine
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 225 Accepted Submission(s): 58
Problem Description
Long long ago, there is a gold mine.The mine consist of many layout, so some area is easy to dig, but some is very hard to dig.To dig one gold, we should cost some value and then gain some value. There are many area that have gold, because of the layout, if one people want to dig one gold in some layout, he must dig some gold on some layout that above this gold's layout. A gold seeker come here to dig gold.The question is how much value the gold he can dig, suppose he have infinite money in the begin.
Input
First line the case number.(<=10)
Then for every case:
one line for layout number.(<=100)
for every layout
first line gold number(<=25)
then one line for the dig cost and the gold value(32bit integer), the related gold number that must be digged first(<=50)
then w lines descripte the related gold followed, each line two number, one layout num, one for the order in that layout
see sample for details
Then for every case:
one line for layout number.(<=100)
for every layout
first line gold number(<=25)
then one line for the dig cost and the gold value(32bit integer), the related gold number that must be digged first(<=50)
then w lines descripte the related gold followed, each line two number, one layout num, one for the order in that layout
see sample for details
Output
Case #x: y.
x for case number, count from 1.
y for the answer.
x for case number, count from 1.
y for the answer.
Sample Input
1
2
1
10 100 0
2
10 100 1
1 1
10 100 1
1 1
2
1
10 100 0
2
10 100 1
1 1
10 100 1
1 1
Sample Output
Case #1: 270
Source
2011 Multi-University Training Contest 16 - Host by TJU
Recommend
lcy
和HDU3917Road constructions几乎一样,http://blog.csdn.net/power721/article/details/6665750
只是收益和支出合并成了一个点
建图:
s到金矿ij连边,边权为支出
金矿ij到t连边,边权为收益
要采金矿j必须先采金矿i,则i到j连边,边权为inf
代码:
#include<cstdio> #include<cstring> #include<vector> #define N 5005 #define M 1000005 #define inf 1ll<<60 #define min(a,b) ((a)<(b)?(a):(b)) using namespace std; __int64 n,m,s,t,num,adj[N],dis[N],q[N]; struct edge { __int64 v,w,pre; }e[M]; void insert(__int64 u,__int64 v,__int64 w) { e[num]=(edge){v,w,adj[u]}; adj[u]=num++; e[num]=(edge){u,0,adj[v]}; adj[v]=num++; } __int64 bfs() { __int64 i,x,v,head=0,tail=0; memset(dis,0,sizeof(dis)); dis[s]=1; q[++tail]=s; while(head!=tail) { x=q[head=(head+1)%N]; for(i=adj[x];~i;i=e[i].pre) if(e[i].w&&!dis[v=e[i].v]) { dis[v]=dis[x]+1; if(v==t) return 1; q[tail=(tail+1)%N]=v; } } return 0; } __int64 dfs(__int64 x,__int64 limit) { if(x==t) return limit; __int64 i,v,tmp,cost=0; for(i=adj[x];~i&&cost<limit;i=e[i].pre) if(e[i].w&&dis[x]==dis[v=e[i].v]-1) { tmp=dfs(v,min(limit-cost,e[i].w)); if(tmp) { e[i].w-=tmp; e[i^1].w+=tmp; cost+=tmp; } else dis[v]=-1; } return cost; } __int64 Dinic() { __int64 ans=0; while(bfs()) ans+=dfs(s,inf); return ans; } int main() { __int64 c,cc=0;scanf("%I64d",&c); while(c--) { __int64 i,j,k,u,v,w1,w2,a,b,idx=2,sum=0,h[105][35]={0}; num=0; memset(adj,-1,sizeof(adj)); s=0; t=1; scanf("%I64d",&n); for(i=0;i<n;i++){scanf("%I64d",&m);for(j=0;j<m;j++){scanf("%I64d%I64d%I64d",&w1,&w2,&k);sum+=w2;u=h[i][j]=idx++;insert(s,u,w1);insert(u,t,w2);while(k--){scanf("%I64d%I64d",&a,&b);v=h[a-1][b-1];insert(v,u,inf);}}} printf("Case #%I64d: %I64d\n",++cc,sum-Dinic()); } }
- HDU3996 Gold Mine最大权闭合图 2011 Multi-University Training Contest 16 - Host by TJU
- HDU3917 Road constructions 最大权闭合图 2011 Multi-University Training Contest 8 - Host by HUST
- HDU3879 Base Station 最大权闭合图/最大密度子图 2011 Multi-University Training Contest 5 - Host by BNU
- 多校第16场 HDU3996 Gold Mine (最大权闭合图)
- HDU3998 Sequence 动态规划+最大流2011 Multi-University Training Contest 16 - Host by TJU
- 2009 Multi-University Training Contest 1 - Host by TJU
- HDU 3879 Base Station 最大权闭包 2011 Multi-University Training Contest 5 - Host by BNU
- HDU 3917 Road constructions 2011 Multi-University Training Contest 8 - Host by HUST 最大权闭包
- 2014 Multi-University Training Contest 10 1001 最大权闭合图
- 2016 Multi-University Training Contest 4 09 String problem (hdu5772) 【最大权闭合子图】
- 最大权闭合图hdu3996
- Wireless Password [ 2009 Multi-University Training Contest 1 - Host by TJU ]
- 2011 Multi-University Training Contest 1 - Host by HNU
- 2011 Multi-University Training Contest 3 - Host by BIT
- hdu 3996 Gold Mine (最大权闭合图)
- 【HDU】3996 Gold Mine 最大权闭合子图
- HDU 3996 Gold Mine 最大权闭合图
- HDU 3996 Gold Mine 最大权闭合图
- 一步一步学Linq to sql(二):DataContext与实体
- android电话应用程序概述
- 菜鸟学习IHttpModule 接口笔记(一)
- Windows虚拟内存问题详解
- 设计模式
- HDU3996 Gold Mine最大权闭合图 2011 Multi-University Training Contest 16 - Host by TJU
- Android-sharedUserId数据权限
- gdb
- 矩阵乘法
- JScript 用正则表达式自定义方法去掉字符串前后的空格
- 一步一步学Linq to sql(三):增删改
- (总结)RHEL/CentOS 5.x使用第三方软件库(EPEL与RPMForge、RPMFusion软件库)
- 怎样才是真正的架构师?(文章收藏)
- Oracle入门心得