机器人走方格(简单DP)

    xiaoxiao2025-11-15  3

    1118 机器人走方格 基准时间限制:1 秒 空间限制:131072 KB 分值: 0  难度:基础题  收藏  关注 M * N的方格,一个机器人从左上走到右下,只能向右或向下走。有多少种不同的走法?由于方法数量可能很大,只需要输出Mod 10^9 + 7的结果。 Input 第1行,2个数M,N,中间用空格隔开。(2 <= m,n <= 1000) Output 输出走法的数量。 Input示例 2 3 Output示例 3 #include <iostream> #include <stdio.h> #include <cstring> #include <algorithm> #include <math.h> #include <iomanip> using namespace std; typedef long long ll; const int maxn=1010; const long mod=1000000007; ll dp[maxn][maxn]; int main() { int m,n; cin>>m>>n; memset(dp,0,sizeof(dp)); for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { if(i==1&&j==1) dp[i][j]=1; else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod; } } cout<<dp[m][n]<<endl; return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1304219.html
    最新回复(0)