第一种:
1<=n,m<=1000,mod<=1e9,用杨辉三角做
例题
#include<stdio.h>
#include <string.h>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=1001;
long long Triangle[N][N];
void creat()
{
Triangle[0][0]=1;
for(int i=1;i<N;i++)
{
Triangle[i][0]=1;
for(int j=1;j<i;j++)
{
Triangle[i][j]=Triangle[i-1][j-1]+Triangle[i-1][j];
}
Triangle[i][i]=1;
}
}
int main()
{
int c;
int a,b;
creat();
while(~scanf("%d",&c))
{
while(c--)
{
scanf("%d%d",&a,&b);
printf("%d\n",(int)(Triangle[a][b]));
}
}
}
/***************************************************
User name: Gitfan
Result: Accepted
Take time: 0ms
Take Memory: 7000KB
Submit time: 2017-02-23 12:19:22
****************************************************/