616 nyoj newbie dp, 616 nyojdp

Source: Internet
Author: User

616 nyoj newbie dp, 616 nyojdp
Newbie dp time limit: 1000 MS | memory limit: 65535 KB difficulty: 3


This is a simple survival game where you control a robot from the starting point () of a board to the ending point (n, m) of the Board ). The rules of the game are described as follows:
1. The robot starts at the starting point of the Board and has the energy marked by the starting point.
2. robots can only go right or down, and each step consumes one unit of energy.
3. Robots cannot stay in place.
4. When the robot selects a feasible path, when he reaches the end of the path, he will only have the energy marked by the end point.

For example, a robot starts at () and has 4 units of energy. The blue square indicates the point he can reach. If the end point he chooses in this path is)

Point. When it reaches (2, 4), it will have 1 unit of energy. This is a way to start the next path selection until it reaches (6, 6.
The question is how many ways robots can go from the start point to the end point. This may be a large number. The output result is a modulo of 10000.

Enter an integer T in the first line to indicate the number of data groups.
For each group of data, enter two integers n, m (1 <= n, m <= 100) in the first row ). Indicates the size of the Board. Next, enter n rows, with m integers e (0 <= e <20) in each row ).
Result of Modulo 10000 for the total number of data output modes of each group.
Sample Input
16 64 5 6 6 4 32 2 3 1 7 21 1 4 6 2 75 8 4 3 9 57 6 6 2 1 53 1 1 3 7 2
Sample output

Liu Cheng

Train of Thought: simulate a robot's walk with a few energy steps and only simulate the path it may walk.

Define dp [I] [j] as the number of conditions to map [I] [j]

Dp [0] [0] = 1;

When map [I] [j] is 0

If (map [I] [j])

For (k = 0; k <= map [I] [j]; k ++)

For (h = 0; h <= map [I] [j]-k; h ++)

If (k! = 0 | h! = 0) & k + I <n & h + j <m) // bottom right walking

Dp [I + k] [h + j] + = dp [I] [j];

#include<iostream>#include<algorithm>#include<string.h>#include<cstdio>#include<cmath>using namespace std;int dp[105][105],map[105][105];int main(){    int t;    cin>>t; while(t--) {     int n,m;     cin>>n>>m;     for(int i=0;i<n;i++)     for(int j=0;j<m;j++)         cin>>map[i][j];        memset(dp,0,sizeof(dp));    dp[0][0]=1;     for(int i=0;i<n;i++)     for(int j=0;j<m;j++)        if(map[i][j])        for(int k=0;k<=map[i][j];k++)        for(int h=0;h<=map[i][j]-k;h++)        {            if((k!=0||h!=0)&&k+i<n&&h+j<m)            dp[i+k][j+h]=(dp[i][j]+dp[i+k][j+h])%10000;        }    cout<<dp[n-1][m-1]<<endl; }}

Related Article

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.