Fork me on GitHub

HDU 6114 Chess

HDU 传送门
很显然,组合数。
输出C(n,m)就可以了。
因为询问比较多,所以用杨辉三角就可以了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#define LL long long
#define MOD 1000000007
using namespace std;
int n,m,T;
LL ans;
LL yh[1009][1009];
int main()
{
    for(int i=0;i<=1005;i++) yh[i][i]=1,yh[i][0]=1;
    for(int i=1;i<=1005;i++) for(int j=1;j<i;j++) yh[i][j]=(yh[i-1][j-1]+yh[i-1][j])%MOD;

    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        if(n<m) swap(n,m);//n>=m
        ans=yh[n][m]; 
        printf("%lld\n",ans);
    }
    return 0;
}
posted @ 2017-09-24 17:48  primes  阅读(93)  评论(0编辑  收藏  举报