组合数的计算方法

C n m C n m % p 计算组合数C^m_n和 C^m_n\%p

#include <stdio.h>


typedef long long LL;
LL res[67][67]={0};
LL cal(LL m,LL n)
{//计算组合数
    if(m==n||m==0)return 1;
    else if(res[m][n]!=0)return res[m][n];
    return res[m][n]=cal(m-1,n-1)+cal(m,n-1);//递归,先进行运算再返回res[m][n]
}


#include <stdio.h>

int res[1010][1010]={0};
int cal2(int m,int n,int p)
{
    if(m==0||m==n)return 1;
    if(res[m][n]!=0)return res[m][n];
    res[m][n]=(cal(m-1,n-1,p)+cal(m,n-1,p))%p;//递归
    return res[m][n];
}



发布了54 篇原创文章 · 获赞 1 · 访问量 515

猜你喜欢

转载自blog.csdn.net/weixin_43370733/article/details/103789609