HDU 1978-How many ways (memory-based search)

Source: Internet
Author: User

HDU 1978-How many ways (memory-based search)
How many waysTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 3105 Accepted Submission (s): 1823


Problem Description 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 and 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.
The first line of Input is an integer T, indicating 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 ).
Output is the result of Modulo 10000 for the total number of data Output modes in 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
3948 enumerate all possible points from the starting point based on the energy, meeting the requirements of I + j <= ma [x] [y], and save the path scheme. Introduction to memory
#include #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include 
           
            #include 
            #include 
             
              #define ll long long#define maxn 116#define pp pair
              
               #define INF 0x3f3f3f3f#define max(x,y) ( ((x) > (y)) ? (x) : (y) )#define min(x,y) ( ((x) > (y)) ? (y) : (x) )using namespace std;int n,m,dp[102][102],ma[102][102];int dfs(int x,int y){if(x==n&&y==m)return 1;if(dp[x][y]!=-1)return dp[x][y];dp[x][y]=0;int s=ma[x][y];for(int i=0;i<=s;i++){for(int j=0;j<=s-i;j++){if(x+i>=1&&x+i<=n&&y+j>=1&&y+j<=m)dp[x][y]=(dp[x][y]+dfs(x+i,y+j))%10000;}}return dp[x][y];}int main(){int T;scanf("%d",&T); while(T--){memset(dp,-1,sizeof(dp));scanf("%d%d",&n,&m);for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&ma[i][j]);printf("%d\n",dfs(1,1)%10000);}return 0;}
              
             
           
          
         
        
       
      
     
    
   
  

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.