基准时间限制: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 <string.h> #include <algorithm> const int MAX = 1010; const int MOD = 1000000007; using namespace std; long long dp[MAX][MAX]; int main() { int n,m; while(~scanf("%d%d",&n,&m)) { memset(dp,0,sizeof(dp)); for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) if(i == 1 && j == 1) dp[i][j] = 1; else dp[i][j] = (dp[i-1][j]+ dp[i][j - 1]) % MOD; printf("%d\n",dp[n][m]); } }