#include <bits/stdc++.h>
using namespace std;
int a[20][20];
int dfs(int n,int m)
{//记忆化搜索
if(a[n][m]!=0)
{
return a[n][m];
}
if(n<m)
{
return 0;
}
if(n==m||m==0)
{
return a[n][m]=1;;
}
if(m==1)
{
a[n][m]=n;
return n;
}
else
{
return a[n][m]=dfs(n-1,m-1)+dfs(n-1,m);//递归算组合数,其实蛮简单的
}
}
int main(void)
{
int n,m;
while(cin>>n>>m)
{
cout <<dfs(n,m)<<endl;
}
return 0;
}
//
//#include <bits/stdc++.h>
//using namespace std;
//string s1;
//string s2;
//int dfs(int n,int m)
//{
// if(n<m)
// {
// return 0;
// }
// if(n==m||m==0)
// {
// return 1;
// }
// if(m==1)
// {
// return n;
// }
// else
// {
// return dfs(n-1,m-1)+dfs(n-1,m);//递归算组合数,其实蛮简单的
// }
//}
//i
记忆化搜索-输出组合数
最新推荐文章于 2020-04-18 11:54:15 发布