设为首页 加入收藏

TOP

POJ 3422 Kaka's Matrix Travels
2015-07-20 17:41:55 来源: 作者: 【 】 浏览:1
Tags:POJ 3422 Kaka' Matrix Travels


K路最大费用最大流,

每个点的值只能取一次: 拆点,一个点的两个部分之间连 1 条费用mp容量一的边,连一条费用0容量很大的边

K次: 源点和汇点拆点,两个部分之间连K条边


Kaka's Matrix Travels
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7985 Accepted: 3191

Description

On an N × N chessboard with a non-negative number in each grid, Kaka starts his matrix travels with SUM = 0. For each travel, Kaka moves one rook from the left-upper grid to the right-bottom one, taking care that the rook moves only to the right or down. Kaka adds the number to SUM in each grid the rook visited, and replaces it with zero. It is not difficult to know the maximum SUMKaka can obtain for his first travel. Now Kaka is wondering what is the maximum SUM he can obtain after his Kth travel. Note the SUM is accumulative during the K travels.

Input

The first line contains two integers N and K (1 ≤ N ≤ 50, 0 ≤ K ≤ 10) described above. The following N lines represents the matrix. You can assume the numbers in the matrix are no more than 1000.

Output

The maximum SUM Kaka can obtain after his Kth travel.

Sample Input

3 2
1 2 3
0 2 1
1 4 2

Sample Output

15

Source

POJ Monthly--2007.10.06, Huang, Jinsong



#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        using namespace std; const int maxn=100100; const int INF=1<<30; struct Edge { int to,next,cap,flow,cost; }edge[maxn*20]; int Adj[maxn],Size,n; void init() { memset(Adj,-1,sizeof(Adj)); Size=0; } 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<<"add :"<
       
         q; for(int i=0;i
        
         edge[i].flow&& dist[v]
         
          edge[i].cap-edge[i].flow) Min=edge[i].cap-edge[i].flow; } 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 N,K; int mp[70][70]; int main() { while(scanf("%d%d",&N,&K)!=EOF) { init(); for(int i=0;i
          
           


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu-1015 Safecracker 下一篇BZOJ 1269 [AHOI2006]文本编辑器e..

评论

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

·MySQL 安装及连接-腾 (2025-12-25 06:20:28)
·MySQL的下载、安装、 (2025-12-25 06:20:26)
·MySQL 中文网:探索 (2025-12-25 06:20:23)
·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)