组合公式

组合公式C(n,m);
http://codevs.cn/problem/1631/

http://baike.baidu.com/link?url=WfX9ZlRyN8huoWRxkjBRCMg0VhG2whWCu-ZwlqIsiY3fvpHbbrCV9Rtjkcqt41_LsERSmxXoIxs5RtQOebdfkIpfmz2Jv-8MAfzrrgFYKkj71D6jazrLAnG11cwdMkiu

暴力就算了


杨辉三角(666)离线
杨辉三角的这个j<
i是可以变成i<
min(i,m+1)的

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define Ll long long
using namespace std;
Ll mo=100003;
Ll C[1001][1001];
int n,m,x,y,z;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<=n;i++)C[i][0]=C[i][i]=1;
    for(int i=2;i<=n;i++)
    for(int j=1;j<i;j++)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
    printf("%lld",C[n][m]);
}

递归调用法(其实就是杨辉三角的在线版)

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define Ll long long
using namespace std;
Ll mo=100003;
Ll b[1001][1001];
Ll n,m,x,y,z;
Ll C(Ll n,Ll m){
    if(b[n][m])return b[n][m];
    if(m==1)return n%mo;
    if(m==0||m==n)return 1;
    if(m>n)return 0;
    b[n][m]=(C(n-1,m)+C(n-1,m-1))%mo;
    return b[n][m];
}
int main()
{
    scanf("%lld%lld",&n,&m);
    printf("%lld",C(n,m));
}
posted @ 2017-02-20 15:33  largecube233  阅读(159)  评论(0编辑  收藏  举报