Noi 2454 Leitao Kitten

Source: Internet
Author: User

2454: Leitao's kitten

Total time limit:

20000ms

Single test point time limit:

10000ms

Memory Limit:

65536kB

Describe

Leitao classmate is very caring, in his dorm, with an injured by the rescue of the kitten (of course, this behavior is against the Student dormitory regulations). Under his care, the kitten soon returned to health, and more lively and lovely.

But one day, Leitao class back to the bedroom, but found that the kitten is missing! After a search, only to find that she is lying on the balcony on the window of the Persimmon tree in a daze ...

On the campus of Peking University, there are many persimmon trees, there are N trees in front of the dormitory building where Leitao is located. And the height of each of the N persimmon trees is H. Winter's cold gradually enveloped the earth, the leaves of the tree gradually fell out, only a yellow of persimmon, looked very gratifying. and Leitao kitten just very love to eat persimmon, look out of the window tree persimmon, she is very envious, so decided to use their agility jumping ability to jump to the tree to eat persimmon.

The kitten can jump from the dorm's balcony to the top of any persimmon tree in the window. After that, she can jump 1 units in the current location along the current Persimmon tree. Of course, the kitten's ability is far more than that, she can also jump between the trees. Each time she can jump from the current tree to another, in the process, her height will drop the Delta unit distance. Every moment, as long as she is in the position of persimmon, she can eat. The whole "Eat persimmon action" until the kitten landed on the ground.

Leitao investigated the growth of persimmon on all persimmon trees. He would like to know, how many persimmon can the kitten eat from the balcony? He knows that writing a program can easily solve the problem, but he is now lazy to write any code. So now your task is to help Leitao write a program like this.

The figure is an example of N = 3, H = ten, and Delta = 2. The kitten jumps according to the route shown and can eat up to 8 Persimmon j

Input

The first line of the input file has three integers separated by spaces, representing N, H, Delta

The next N rows, the first integer for each line, is Ni, representing the number of persimmons on the i tree.

Next is the Ni integer, each integer Tij represents the Tij height of the persimmon tree with a persimmon.

Output

The output contains only one integer, which is the number of persimmons the kitten eats.

Sample input

3 10 2

3 1 4 10

6 3 5 9 7 8 9

5 4 5 3 6 9

Sample output

8

Tips

1 ≤ N, H ≤2000
0≤ Ni ≤5000
1 ≤ DeltaN, 1≤ TijH
Input file size not greater than 40960KB

Source

Excalibur, 2008

Ideas

The DP on the graph.

A Tree of n tall h is treated as a graph of a width n high h, and the maximum number of persimmons obtained by setting D[I][J] has a transfer type:

d[i][j]=max{D[i-1][j], D[i-delta][k]}

Note that the number of rows for the second item is I-delta, and the maximum of D for a row is maintained with an array of MAXV, which can be transferred at O (1) time.

Code

1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5 6 Const intMAXN = -+Ten;7 8 intD[MAXN][MAXN];9 intG[MAXN][MAXN];Ten intMAXV[MAXN]; One  A intN,h,delta; -  - intRead () { the     CharC=GetChar (); -      while(!isdigit (c)) c=GetChar (); -     intx=0; -      while(IsDigit (c)) { +x=x*Ten+c-'0'; -C=GetChar (); +     } A     returnx; at } -  - intMain () { -N=read (), H=read (), delta=read (); -      for(intI=1; i<=n;i++) { -         ints,x; ins=read (); -          for(intj=1; j<=s;j++){ tox=read (); +g[i][x]++; -         } the     } *     intans=0; $      for(intI=1; i<=h;i++) {Panax Notoginsengmaxv[i]=0; -          for(intj=1; j<=n;j++) { the             if(i>1) d[i][j]=d[i-1][j]; +             if(I>delta) D[i][j]=max (d[i][j],maxv[i-Delta]); Ad[i][j]+=G[j][i]; themaxv[i]=Max (maxv[i],d[i][j]); +             if(i==h) ans=Max (ans,d[i][j]); -         } $     } $printf"%d\n", ans); -     return 0; -}

Noi 2454 Leitao Kitten

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.