2014多校10(1005)hdu4975(网络流isap+判断唯一性)

A simple Gaussian elimination problem.

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 658    Accepted Submission(s): 221


Problem Description
Dragon is studying math. One day, he drew a table with several rows and columns, randomly wrote numbers on each elements of the table. Then he counted the sum of each row and column. Since he thought the map will be useless after he got the sums, he destroyed the table after that.

However Dragon's mom came back and found what he had done. She would give dragon a feast if Dragon could reconstruct the table, otherwise keep Dragon hungry. Dragon is so young and so simple so that the original numbers in the table are one-digit number (e.g. 0-9).

Could you help Dragon to do that?
 

Input
The first line of input contains only one integer, T(<=30), the number of test cases. Following T blocks, each block describes one test case.

There are three lines for each block. The first line contains two integers N(<=500) and M(<=500), showing the number of rows and columns.

The second line contains N integer show the sum of each row.

The third line contains M integer show the sum of each column.
 

Output
Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. For each case, if we cannot get the original table, just output: "So naive!", else if we can reconstruct the table by more than one ways, you should output one line contains only: "So young!", otherwise (only one way to reconstruct the table) you should output: "So simple!".
 

Sample Input
   
   
3 1 1 5 5 2 2 0 10 0 10 2 2 2 2 2 2
 

Sample Output
   
   
Case #1: So simple! Case #2: So naive! Case #3: So young!

题意:给出n行,m列的和,然后每个格子只能是0~9的数,问你有没有一种填数的方案使得满足给出的数据

思路:这题跟hdu4888基本是一模一样,但这题比较卡时间,网络流dinic,isap都能过,时间卡在最后的判环,只要在找环的时候边dfs边把走过的边删掉就好了

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         using namespace std; #define maxn 300000 #define INF ((1<<31)-1) struct node{ int u; int v; int f; int cf; }; int n,m,k; int level[1050]; int vis[1050]; int cur[1050]; int p[1050]; int num[1050]; int head[1050]; node edge[maxn<<1]; int next[maxn<<1]; int d; int S,T; int mini(int x,int y) { return x 
        
          edge[i].cf){ ok=1; cur[x]=i; p[edge[i].v]=i; x=edge[i].v; break; } if(!ok){ if(--num[level[x]]==0)break; level[x]=vn; for(i=head[x];i!=-1;i=next[i])if(edge[i].f>edge[i].cf&&level[edge[i].v]+1 
         
           0)if(dfs(edge[i].v,u))return 1; vis[u]=0; return 0; } inline int get(){ int ret=0; char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)){ ret=ret*10+(int)(c-'0'); c=getchar(); } return ret; } int aa[550]; int bb[550]; int main() { int i,j,w,ttt=0; int t; t=get(); while(t--) { n=get();m=get(); int hehe=0,to=0; for(i=1;i<=n;i++){ w=get(); aa[i]=w; hehe+=w; } for(i=1;i<=m;i++){ w=get(); bb[i]=w; to+=w; } printf("Case #%d: ",++ttt); if(hehe!=to){ puts("So naive!"); continue; } memset(head,-1,sizeof(head)); S=0;T=n+m+1;d=0; for(i=1;i<=n;i++){ add(S,i,aa[i]); add(i,S,0); } for(i=1;i<=n;i++) for(j=1;j<=m;j++) { add(i,n+j,9); add(n+j,i,0); } for(i=1;i<=m;i++){ add(n+i,T,bb[i]); add(T,n+i,0); } if(maxflow(S,T,n+m+2)!=to)puts("So naive!"); else { memset(vis,0,sizeof(vis)); int flagg=0; for(i=1;i<=n;i++)if(dfs(i,-1)){ flagg=1; puts("So young!"); break; } if(flagg==0) puts("So simple!"); } } return 0; } 
          
         
       
      
      
     
     
    
    
   
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值