POJ 2396 determining feasible solutions of the upper and lower bounds of the active sink

Source: Internet
Author: User

POJ 2396 determining feasible solutions of the upper and lower bounds of the active sink

Question: there is a series of n rows and m columns. The values and values of each element and value in each column are given to you. The following are restrictions on element values, for example, 0 0> 1 indicates that all elements in the series are greater than 1 and 0 indicates all, 0 1 indicates the first element of all rows, and 1 0 indicates the first row, then, determine whether there is a solution when the series meets these conditions.

Train of Thought: the condition is to give you the upper and lower bounds, and then this question is the source sink point, the Source Vertex connects rows, the column connects to the sink point, similar to hdu 4975 with HDU4975, then, the source sink point is converted to a non-source sink. You only need to connect a sink point to the inf edge of the source sink point. Then, like the method of a non-source sink, we recommend that you do not study it first, then judge whether the stream is full to determine whether there is any solution, but at last we need to remove the edge of the Source and Sink points from the source point to the sink point. This is because we used to determine whether there was any solution, however, there is a possibility that the network can continue to flow. After running, all sums are assigned

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include #include 
       
        using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;const int maxn=260;struct edge{ int to,cap,rev; edge(){} edge(int a,int b,int c){to=a;cap=b;rev=c;}};vector
        
          G[maxn];int level[maxn],iter[maxn],flag;void add_edge(int from,int to,int cap){ G[from].push_back(edge(to,cap,G[to].size())); G[to].push_back(edge(from,0,G[from].size()-1));}void bfs(int s){ memset(level,-1,sizeof(level)); queue
         
          que; level[s]=0;que.push(s); while(!que.empty()){ int v=que.front();que.pop(); for(unsigned int i=0;i
          
           0&&level[e.to]<0){ level[e.to]=level[v]+1; que.push(e.to); } } }}int dfs(int v,int t,int f){ if(v==t) return f; for(int &i=iter[v];i
           
            0&&level[v]
            
             0){ e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0;}int max_flow(int s,int t){ int flow=0; while(1){ bfs(s); if(level[t]<0) return flow; memset(iter,0,sizeof(iter)); int f; while((f=dfs(s,t,inf))>0) flow+=f; }}int L[maxn][maxn],R[maxn][maxn],n,m;void slove(int ask){ int a,b,d; char ch; for(int k=0;k'){ for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ if(R[i][j+n]<=d) flag=1; L[i][j+n]=max(L[i][j+n],d+1); } }else if(ch=='='){ for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ if(L[i][j+n]>d) flag=1; if(R[i][j+n]
             
              =d) flag=1; R[i][j+n]=min(R[i][j+n],d-1); } } } if(a==0&&b!=0){ if(ch=='>'){ for(int i=1;i<=n;i++){ if(R[i][b+n]<=d) flag=1; L[i][b+n]=max(L[i][b+n],d+1); } }else if(ch=='='){ for(int i=1;i<=n;i++){ if(L[i][b+n]>d) flag=1; if(R[i][b+n]
              
               =d) flag=1; R[i][b+n]=min(R[i][b+n],d-1); } } } if(b==0&&a!=0){ if(ch=='>'){ for(int i=1;i<=m;i++){ if(R[a][i+n]<=d) flag=1; L[a][i+n]=max(L[a][i+n],d+1); } }else if(ch=='='){ for(int i=1;i<=m;i++){ if(L[a][i+n]>d) flag=1; if(R[a][i+n]
               
                =d) flag=1; R[a][i+n]=min(R[a][i+n],d-1); } } } if(a!=0&&b!=0){ if(ch=='>'){ if(R[a][b+n]<=d) flag=1; L[a][b+n]=max(L[a][b+n],d+1); }else if(ch=='='){ if(R[a][b+n]
                
                 d) flag=1; L[a][b+n]=R[a][b+n]=d; }else if(ch=='<'){ if(L[a][b+n]>=d) flag=1; R[a][b+n]=min(R[a][b+n],d-1); } } }}int num[10010][5];int main(){ int T1,a,ask; scanf("%d",&T1); while(T1--){ scanf("%d%d",&n,&m); for(int i=0;i
                 
                
               
              
             
            
           
          
         
        
       
      
     
    
   
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.