HDU6114 Chess(组合数)

来源:互联网 发布:淘宝客推广流量怎么样 编辑:程序博客网 时间:2024/06/18 10:30
/*组合数在一共N×M个点的矩形棋盘中摆最多个数的車使其互不攻击的方案数对于任何一个車A,如果有其他一个車B在它的上方(車B行号小于車A),那么車A必须在車B的右边(車A列号大于車B)。ans=C(max(m,n),min(m,n))*/#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>using namespace std;typedef long long LL;LL n,m;const int mod=1e9+7;const int maxn=1000+5;LL c[maxn][maxn];void init()//预处理组合数{    for(int i=0;i<maxn;i++)    {        c[i][0]=1;        for(int j=1;j<=i;j++)        {            c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;        }    }}int main(){    int t;    init();    scanf("%d",&t);    while(t--)    {        scanf("%I64d %I64d",&n,&m);        if(n>m) swap(n,m);        printf("%I64d\n",c[m][n]%mod);    }    return 0;}