Rokua P1373 Small A and Uim escape

Source: Internet
Author: User

Topic background

Little A and uim came to the rainforest to explore. Suddenly a gust of wind came, a cloud of clouds from the northern horizon rushed over, accompanied by a road of lightning, bursts of thunder. In an instant, the wind, black clouds covered the sky, followed by the big rain drops from the sky, saw a disheveled, bloody fangs monster, low voice said: "Oh, since you came here, can only survive one!" ”。 Little A and his little friends were stunned!

Title Description

In a moment, the ground appears a n*m giant matrix, each lattice on the matrix has a lump of 0~k not equal amount of magic liquid. The monsters each gave small A and uim a magic bottle, said, you can start from any grid of the matrix, each time to the right or down one step, from any lattice end. Start small A with the magic bottle to absorb the magic liquid on the ground, the next step by uim absorption, so alternating, and requires the final step must be absorbed by UIM. Magic bottle only k capacity, that is, if installed k+1 then the Magic bottle will be emptied into 0, if installed k+2 only 1 left, and so on. The monster also said, the last who bottle of magic liquid more, who will survive. Small A and uim feelings deep, brother, how can bear to let small partners away from their own? Silence for a moment, small a brainwave, if they two of the magic bottle man possessed as much as the liquid, not all can survive it? Little A and his little friends laughed!

Now he wants to know how many ways they can survive.

Input/output format

Input format:

The first line, three spaces separated by an integer n,m,k

The next n rows, m columns, represent the amount of magic fluid per one of the matrices. The numbers on the same line are separated by a space.

Output format:

An integer that represents the number of methods. Due to the possible large, output to 1 000 000 007 after the result of the remainder.

Input and Output Sample input example # #:
2 2 31) 11 1
Sample # # of output:
4
Description

"Source of the topic"

LZN adaptation

"Sample Interpretation"

Sample interpretation: Four options are: (+), (2,1), (2,2), (2,1), (2,2).

"Data Range"

For 20% of data, n,m<=10,k<=2

For 50% of data, n,m<=100,k<=5

For 100% of data, n,m<=800,1<=k<=15

A DP.

1#include <iostream>2#include <cstdio>3 Const intN = -+ One, mod =1000000007 ;4 using namespacestd;5 intn,m,k,a[n][n],f[n][n][ -][2];6 7 voidInit ()8 {9scanf"%d%d%d", &n,&m,&k); + +K;Ten      for(intx =1; x <= N; ++x) One          for(inty =1; y <= m; ++y) A         { -scanf"%d",&a[x][y]); -f[x][y][a[x][y]%k][0] =1; the         } - } -  - voidSolve () + { -      for(inti =1; I <= N; ++i) +          for(intj =1; J <= M; ++j) A              for(inth =0; H < K; ++h) at             { -f[i][j][h][0] + = f[i-1][j][(H+k-a[i][j])%k][1] + f[i][j-1[(H+k-a[i][j])%k][1]; -f[i][j][h][1] + = f[i-1][j][(H+a[i][j])%k][0] + f[i][j-1[(H+a[i][j])%k][0]; -f[i][j][h][0] %=MoD; -f[i][j][h][1] %=MoD; -             } in     intAns =0; -      for(inti =1; I <= N; ++i) to          for(intj =1; J <= M; ++j) +Ans = (ans + f[i][j][0][1] ) %MoD; -printf"%d\n", ans); the } *  $ intMain ()Panax Notoginseng { - //freopen ("1373.in", "R", stdin); the //freopen ("1373.out", "w", stdout); + Init (); A Solve (); the fclose (stdin); + fclose (stdout); -     return 0; $}

Rokua P1373 Small A and Uim escape

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.