The game problem of codevs1033 earthworms

Source: Internet
Author: User

Description

On a trapezoidal field, a group of earthworms are doing a collection of food games. The earthworms piled up the food on the trapezoidal field as follows:

A (a) a (1,m)

A (2,1) a (2,2) a (2,3) ... a (2,m) a (2,m+1)

A (3,1) a (3,2) a (3,3) ... a (3,m+1) a (3,m+2)

......

A (n,1) a (n,2) a (n,3) ... a (n,m+n-1)

They divide the food into n rows, the 1th row is the food of the M heap, and the amount of food per heap is a (a), A (,..., a (1,m);

The 2nd row has m+1 heap food, each pile of food quantity is a (2,1), A (2,2),..., A (2,m+1), the following successively M+2 heap, m+3 heap 、... m+n-1 heap food.

Now earthworms have chosen K-worms to test their ability to cooperate (1≤K≤M). The test method is as follows: 1th earthworms choose a pile of food from line 1th, then crawl to the lower left or right, and collect 1 piles of food, for example, from a (2,2) or a (2,3), and not climb to other places. Then crawl down one line and collect a bunch of food until the nth row collects a bunch of food. 1th The amount of food collected by earthworms is the sum of the amount of food it collects in each row; the 2nd worm also climbs from line 1th to Nth row, each row collects a pile of food, crawls the method is similar with the 1th worm, but cannot meet the 1th worm to climb the trajectory; In general, the first earthworm crawls from the 1th line to the nth row, Collect a pile of food per row, the method of crawling is similar to the 1th earthworm, but can not meet the previous I-1 of the worm crawling trajectory. How should this K-worm work together to make the largest amount of food they collect? The amount of food collected can represent the level of cooperation of this K-worm.

    • Ø Programming tasks:

Given the trapezoidal m, n, and K values (1≤K≤M≤30;1≤N≤30) and the amount of food per pile in the ladder (non-integers less than 10), the maximum amount of food that can be collected by this K-worm is programmed.

Input Description

The input data is provided by a text file named Input1.*, with a total of n+1 lines. Each row is separated by a space between two data.

The 1th line is the values of N, M, and K.

The next n rows are the trapezoid of each row of food volume A (i,1), A (i,2), ..., a (i,m+i-1), i=1,2,..., N.

Output Description

At the end of the program, the maximum amount of food that can be collected by the K earthworm Bar is output on the screen.

Sample Input

3 2 2

1 2

5 0 2

1 10 0 6

Sample Output

26

Do the codevs1227 box to take the number 2 and then do this problem is very simple. The same modeling method, the same cost flow. For more information, please see Codevs 1227-square Check number 2

Why do we have to split a point into two? In fact, only then can we control a point only to be counted as a contribution in order to ensure that the answer is correct.

The code is as follows:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 #defineFile (s) freopen (S ".", "R", stdin), Freopen (S ". Out", "w", stdout)7 #defineMAXN 1000108 #defineINF 21474836479 #defineR (J) (J^1)Ten  One using namespacestd; AtypedefLong LongLlg; -  - intN,M,K,JIA,S,T,ANS,L,R,DIS[MAXN],FF[MAXN],FA[MAXN],D1[MAXN],D[MAXN]; the inthead[maxn],next[maxn],to[maxn],f[maxn],c[maxn],tt=1, s1,t1; - BOOLW[MAXN]; -  - voidLinkintXintYintZinto) { +to[++tt]=y;next[tt]=head[x];head[x]=tt; -to[++tt]=x;next[tt]=head[y];head[y]=tt; +c[tt-1]=z; f[tt-1]=o; f[tt]=-o; A } at  - BOOLSPFA () { -      for(intI=1; i<=t;i++) dis[i]=-inf,d1[i]=INF; -L=r=0; D[r++]=s; dis[s]=0; d1[s]=INF; -      while(l!=R) { -         intU=d[l++]; w[u]=0; in         if(L&GT;=MAXN) l=0; -          for(intI=head[u],v;v=to[i],i;i=Next[i]) to             if(c[i]>0&& dis[v]<dis[u]+F[i]) { +dis[v]=dis[u]+F[i]; -Ff[v]=i; fa[v]=u; thed1[v]=min (d1[u],c[i]); *                 if(!W[v]) { $w[v]=1;d [r++]=v;Panax Notoginseng                     if(R&GT;=MAXN) r=0; -                 } the             } +     } A     if(Dis[t]==-inf)return 0; theans+=dis[t]*D1[t]; +      for(intnow=t;now!=s;now=Fa[now]) { -c[ff[now]]-=D1[t]; $C[r (Ff[now])]+=D1[t]; $     } -     return 1; - } the  - intMain () {WuyiFile ("a"); thescanf" %d%d%d",&n,&m,&k); -Jia= (m*2+n-1) *n/2; Wus1=jia*2+1; t1=s1+1; s=t1+1; t=s+1; -Link (s,s1,k,0); Link (t1,t,k,0); About      for(intI=1, now=1; i<=n;i++) $          for(intj=1, x;j<m+i;j++,now++){ -scanf"%d",&x); -             if(i==1) Link (s1,now,1,0); -Link (Now,now+jia,1, x); A             if(i!=N) { +Link (now+jia,now+m+i-1,1,0); theLink (now+jia,now+m+i,1,0); -             } $             ElseLink (now+jia,t1,1,0); the         } the      while(SPFA ()); theprintf"%d", ans); the     return 0; -}

The game problem of codevs1033 earthworms

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.