How many ways
Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) total submission (s): 4275 Accepted Submission (s): 2499
Problem description This is a simple survival game where you control a robot to go from the starting point of a chessboard to the end of the chessboard (n,m). The rules of the game are described as follows: 1. The robot starts at the starting point of the chessboard and has the energy that is marked at the starting point. 2. The robot can only walk to the right or down, and consumes one unit of energy per step. 3. The robot can not stay in situ. 4. When the robot chooses a workable path, when he goes to the end of the path, he will have only the energy marked by the end point. For example, when a robot starts at (a) point and has 4 units of energy, the blue squares indicate the point at which he can reach, if he chooses the destination in this path selection (2,4)
Point, when he arrives (2,4) the point will have 1 units of energy and start the next path selection until the (6,6) point is reached. Our question is how many ways a robot is going from the beginning to the end. This can be a large number, the output of the result of 10000 modulo. input The first line, enter an integer t that represents the number of groups of data. For each set of data, enter two integers n,m (1 <= n,m <= 100) for the first row. Represents the size of the board. Next, enter n lines, each of M integers e (0 <= E < 20). output The result of 10000 modulo for the total number of data output modes for each group. sample Input16 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 Output3948 Solution: The memory search, the beginning to the end of the method is 1, return forward; Dp[x][y] represents the number of methods from X, Y to the end of the method; previously searched directly; Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath> #include <vector>using namespace std;const int inf=0x3f3f3f3f; #define MEM (x, y) memset (x,y,sizeof (×)) # Define SI (x) scanf ("%d", &x) #define PI (x) printf ("%d", x) #define SD (y) scanf ("%lf%lf", &x,&y) #define P_ printf ("") const int Mod=10000;const int Maxn=110;int dp[maxn][maxn],mp[maxn][maxn];typedef long long ll;int n,m;int DFS ( int X,int y) {if (dp[x][y]>=0) return dp[x][y];//previously searched for direct return; dp[x][y]=0;for (int i=0;i<=mp[x][y];i++) for (int j=0;j <=mp[x][y]-i;j++) {//Total steps of mp[x][y] if (x+i>n| | Y+J>M) continue; Dp[x][y]= (Dp[x][y]+dfs (x+i,y+j))%mod;} return dp[x][y];} int main () {int t;si (T), while (t--) {si (N), Si (M), mem (dp,-1), for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {si (mp[i ][J]);}} dp[n][m]=1;printf ("%d\n", Dfs);} return 0;}
How many ways (memory search)