HDU 2686 Matrix (maximum cost Stream)

Source: Internet
Author: User

HDU 2686 Matrix (maximum cost Stream)
MatrixTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1890 Accepted Submission (s): 1005



Problem Description Yifenfei very like play a number game in the n * n Matrix. A positive integer number is put in each area of the Matrix.
Every time yifenfei shocould to do is that choose a detour which frome the top left point to the bottom right point and than back to the top left point with the maximal values of sum integers that area matrix yifenfei choose. but from the top to the bottom can only choose right and down, from the bottom to the top can only choose left and up. and yifenfei can not pass the same area of the Matrix before t the start and end.

Input The input contains multiple test cases.
Each case first line given the integer n (2 Than n lines, each line include n positive integers. (<100)

Output For each test case output the maximal values yifenfei can get.
Sample Input

210 35 10310 3 32 5 36 7 1051 2 3 4 52 3 4 5 63 4 5 6 74 5 6 7 85 6 7 8 9

Sample Output
284680

Author yifenfei
Source ZJFC 2009-3 Programming Contest. From (0, 0) to (n-1, n-1) (left-to-right or top-to-bottom only) and then back to (0, 0) (right-to-left or bottom-up only) what is the maximum sum of vertices? Each vertex can only go once. Solution: Find the two greatest paths from (0, 0) to (n-1, n-1. Each edge capacity is 1, cost: For the vertex itself, the edge weight is the vertex weight, and the edge weight of non-vertex is 0.
# Include
 
  
# Include
  
   
# Include
   
    
Using namespace std; const int MAXN = 10010; const int MAXM = 1001000; const int INF = 1 <30; struct EDG {int to, next, cap, flow; int cost; // unit price} edg [MAXM]; int head [MAXN], eid; int pre [MAXN], cost [MAXN]; // point 0 ~ (N-1) void init () {eid = 0; memset (head,-1, sizeof (head);} void addEdg (int u, int v, int cap, int cst) {edg [eid]. to = v; edg [eid]. next = head [u]; edg [eid]. cost = cst; edg [eid]. cap = cap; edg [eid]. flow = 0; head [u] = eid ++; edg [eid]. to = u; edg [eid]. next = head [v]; edg [eid]. cost =-cst; edg [eid]. cap = 0; edg [eid]. flow = 0; head [v] = eid ++;} bool inq [MAXN]; bool spfa (int sNode, int eNode, int n) {queue
    
     
Q; for (int I = 0; I
     
      
0 & cost [v]
      
        0) {init (); for (int I = 0; I
       
         1) maxCost + = mapt [n-1] [n-1]; minCost_maxFlow (s, t, maxCost, n * 2); printf ("% d \ n ", maxCost );}}
       
      
     
    
   
  
 


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.