POJ 3680 Intervals (minimum fee Stream)

Source: Internet
Author: User
Tags bitset

POJ 3680 Intervals (minimum fee Stream)

Question: n intervals. Each interval has a value. You can select several intervals so that no vertex is overwritten for more than k times.

Train of Thought: We can discretization the range endpoint and run the expense stream, no more than k times, we can set this corresponding traffic attribute. It is easy to think that the interval endpoint is used as the node, and the cost of connecting a traffic is-a [I]. the side of c, because we can skip some points, we use traffic INF between each adjacent endpoint, the cost is 0 side connection, then the source traffic is k, the sink traffic is k, when the stream is full, the maximum cost is obtained, and the coverage of each node cannot exceed k times.

Finally, let's talk about the traffic feature. Why is the maximum flow equal to the minimum cut? It is actually very simple, because the maximum flow limit of a route is the smallest traffic.

For details, see the code:

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include
          
            # Include
           
             # Include
            
              # Include
             # Include
              
                # Define Max (a, B) (a)> (B )? (A) :( B) # define Min (a, B) (a) <(B )? (A) :( B) using namespace std; typedef long ll; typedef long double ld; const ld eps = 1e-9, PI = 3.1415926535897932384626433832795; const int mod = 1000000000 + 7; const int INF = 0x3f3f3f; // & 0x7FFFFFFFconst int seed = 131; const ll INF64 = ll (1e18); const int maxn = 500; struct Edge {int from, to, cap, flow, cost;}; struct MCMF {int n, m, s, t; vector
               
                 Edges; vector
                
                  G [maxn]; int inq [maxn]; // whether int d [maxn] is in the queue; // Bellman-Ford int p [maxn]; // The Last arc int a [maxn]; // void init (int n) {this-> n = n; for (int I = 0; I <n; I ++) G [I]. clear (); edges. clear ();} void AddEdge (int from, int to, int cap, int cost) {edges. push_back (Edge) {from, to, cap, 0, cost}); edges. push_back (Edge) {to, from, 0, 0,-cost}); m = edges. size (); G [from]. push_back (m-2); G [to]. push_back (m-1);} bool BellmanFord (int s, int t, int & flow, int & cost) {for (int I = 0; I <n; I ++) d [I] = INF; memset (inq, 0, sizeof (inq); d [s] = 0; inq [s] = 1; p [s] = 0; a [s] = INF; queue
                 
                   Q; Q. push (s); while (! Q. empty () {int u = Q. front (); Q. pop (); inq [u] = 0; for (int I = 0; I <G [u]. size (); I ++) {Edge & e = edges [G [u] [I]; if (e. cap> e. flow & d [e. to]> d [u] + e. cost) {d [e. to] = d [u] + e. cost; p [e. to] = G [u] [I]; a [e. to] = min (a [u], e. cap-e. flow); if (! Inq [e. to]) {Q. push (e. to); inq [e. to] = 1 ;}}}if (d [t] = INF) return false; flow + = a [t]; cost + = d [t] * a [t]; int u = t; while (u! = S) {edges [p [u]. flow + = a [t]; edges [p [u] ^ 1]. flow-= a [t]; u = edges [p [u]. from;} return true;} // you must ensure that there is no negative weight circle int Mincost (int s, int t) {int cost = 0, flow = 0; while (BellmanFord (s, t, flow, cost); return cost ;}}; struct node {int a, B, c ;}a [maxn]; MCMF g; int T, n, k, B [maxn]; int main () {scanf ("% d", & T); while (T --) {scanf ("% d", & n, & k); int cnt = 0; 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.