Problem : 递归求组合数加强版本
Time Limit: 1 Sec Memory Limit: 512 MB
Submit: 634 Solved: 179
[Submit][Status][Web Board]
Description
编一递归程序,求组合数 C(n,m)
已知 C(n,m)=C(n-1,m)+C(n-1,m-1);
Input
一行两个数字N,M,其值小于等于5000
Output
方案数%1000000007
Sample Input
1 1
Sample Output
1
HINT
普通递归写不出哦
记忆化搜索
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll tot[5050][5050];
int f(ll n,ll m){
if(n<=m||m==0){
tot[n][m]=1;
return tot[n][m];
}
else if(tot[n][m]>0)
return tot[n][m];
else tot[n][m]= (f(n-1,m)+f(n-1,m-1))%1000000007;
}
int main(){
ll n,m;
cin>>n>>m;
cout<<f(n,m);