题解 | #走方格的方案数#
走方格的方案数
https://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
#include <iostream> #include <sstream> using namespace std; int main(){ string s; getline(cin,s); istringstream is(s); int m = 0; int n = 0; is>>m>>n; int dp[m+2][n+2]; for(int j = 0;j<=n+1;j++){ dp[0][j] = 0; } for(int i = 0;i<=m+1;i++){ dp[i][0] = 0; } for(int i = 1;i<=m+1;i++){ for(int j = 1;j<=n+1;j++){ if(i == j&&i==1){ dp[i][j] = 1; continue; } dp[i][j] = dp[i-1][j]+dp[i][j-1]; //cout<<dp[i][j]<<endl; } } cout<<dp[m+1][n+1]; } // 64 位输出请用 printf("%lld")
多初始化一行一列免去判断是否大于0