题解 | #走方格的方案数#
走方格的方案数
https://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
#include<iostream>
#include<map>
#include<utility>
using namespace std;
int f(int m,int n);
int main(){
int m,n;cin>>n>>m;
cout<<f(m+1,n+1);
}
map<pair<int,int>, int > map1;
//int 记录pair1出现的次数
int f(int m,int n){
if(map1.find({m,n})!=map1.end())return map1[{m,n}];
if(m==1||n==1)return 1;
else {
map1[{m,n}]=f(m-1,n)+f(m,n-1);
return f(m-1,n)+f(m,n-1);
}
}
#include<map>
#include<utility>
using namespace std;
int f(int m,int n);
int main(){
int m,n;cin>>n>>m;
cout<<f(m+1,n+1);
}
map<pair<int,int>, int > map1;
//int 记录pair1出现的次数
int f(int m,int n){
if(map1.find({m,n})!=map1.end())return map1[{m,n}];
if(m==1||n==1)return 1;
else {
map1[{m,n}]=f(m-1,n)+f(m,n-1);
return f(m-1,n)+f(m,n-1);
}
}

