POJ 1698 網路流最大流水題

來源:互聯網
上載者:User

赤裸裸的網路最大流...建圖還是沒有什麼技巧的... 繼續水...

#include<iostream>#include<string>#include<cstdio>#define MN 444using namespace std;int s,t,ans,w[8],Sum;int map[MN][MN],vis[MN],a[MN],pre[MN],que[MN];void setG(){  Sum=0;s=0;ans=0;  int n,d,l,i,j,a,b,m=0;  memset( map,0,sizeof(map) );  scanf( "%d",&n );  for( i=1;i<=n;i++ )  {    for( j=1;j<=7;j++ )       scanf( "%d",&w[j] );    scanf( "%d%d",&map[0][i],&l );    m=max(l,m);    Sum+=map[0][i];    for( a=0;a<l;a++ )    for( b=1;b<=7;b++ )       if( w[b] ) map[i][n+a*7+b]=1; } t=m*7+n+1; for( i=n+1;i<t;i++ )   map[i][t]=1;}bool bfs(){  int head=0,foot=0;  memset( vis,0,sizeof(vis) );  memset( a,0,sizeof(a) );  que[foot++]=s;  vis[s]=true;  a[s]=INT_MAX;  while( head<foot )  {  int u=que[head++];  for( int i=0;i<=t;i++ )  {  if( !vis[i]&&map[u][i] )  {   a[i]=min( a[u],map[u][i] );   vis[i]=true;   pre[i]=u;   que[foot++]=i;   if( i==t )return true; }   } } return false;  }void EK(){  while( bfs() ){ int m=t; ans+=a[t];  while( m!=s ){   map[pre[m]][m]-=a[t];     map[m][pre[m]]+=a[t];     m=pre[m];   } } printf( ans==Sum?"Yes\n":"No\n" );}int main(){ int T;scanf( "%d",&T ); while( T-- ){    setG();    EK();  }  return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.