设为首页 加入收藏

TOP

HDOJ 3376 Matrix Again
2015-07-20 17:42:26 来源: 作者: 【 】 浏览:1
Tags:HDOJ 3376 Matrix Again


和HDOJ 2686 一样,只是范围不同

最大费用最大流。。。。。

与最小费用最大流的区别用////////////标出来了


对于detour,在源点和汇点处的边的流量为2

对于每个点只能经过一次,拆点,两个点直接建一条流量为1,费用为mp【i】【j】的边

对于每个点可以走到他的左边和下边:连一个费用为0流量大于1的边

Matrix Again

Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 2880 Accepted Submission(s): 846


Problem Description Starvae 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 starvae should to do is that choose a detour which from 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 of Matrix starvae 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 starvae can not pass the same area of the Matrix except the start and end..
Do you know why call this problem as “Matrix Again”? AS it is like the problem 2686 of HDU.

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

Output For each test case output the maximal values starvae can get.
Sample Input
2
10 3
5 10
3
10 3 3
2 5 3
6 7 10
5
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9

Sample Output
28
46
80

Author Starvae
Source HDOJ Monthly Contest ? 2010.04.04
Recommend lcy | We have carefully selected several similar problems for you: 3416 3081 3572 1853 1565
Statistic | Submit | Discuss | Note


#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        using namespace std; const int maxn=800000; const int INF=0x3f3f3f3f; const int inf=9999; struct Edge { int to,next,cap,flow,cost; }edge[4000000]; int Adj[maxn],Size,N,n; void init() { Size=0; memset(Adj,-1,sizeof(Adj)); } void addedge(int u,int v,int cap,int cost) { edge[Size].to=v; edge[Size].next=Adj[u]; edge[Size].cost=cost; edge[Size].cap=cap; edge[Size].flow=0; Adj[u]=Size++; } void Add_Edge(int u,int v,int cap,int cost) { //cout<
       
         q; for(int i=0;i
        
         edge[i].flow&& dist[v]
         
          edge[i].cap-edge[i].flow) Min=edge[i].cap-edge[i].flow; } if(Min==0) break; for(int i=pre[t];~i;i=pre[edge[i^1].to]) { edge[i].flow+=Min; edge[i^1].flow-=Min; cost+=edge[i].cost*Min; } flow+=Min; } return flow; } int mp[1000][1000]; int main() { while(scanf("%d",&N)!=EOF) { for(int i=0;i
          
           


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 4777 Rabbit Kingdom(离线树.. 下一篇STL algorithm算法find_first_of(..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·工业机器人TCP校准中 (2025-12-25 05:19:17)
·opc 通讯协议与 TCP (2025-12-25 05:19:15)
·labview中tcp/ip通信 (2025-12-25 05:19:13)
·新书介绍《Python数 (2025-12-25 04:49:47)
·怎么利用 Python 进 (2025-12-25 04:49:45)