题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6114
题意:中文题
解析:由于题目限制的比较死,上一行的棋子必须在这一行的左边,那么对于一个正方形的棋盘来说,方法数肯定是1的,如果是一个长方形棋盘n*m来说,那就相当于从max(m,n)中选min(m,n)出来,每一列放一个,所以答案就是组合数C(max(n,m),min(n,m)),再加上一个逆元即可
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int mod = 1e9+7;
typedef long long ll;
ll h[maxn];
ll qpow(ll x,ll n)
{
ll res = 1;
while(n)
{
if(n&1)
res = res*x%mod;
x = x*x%mod;
n >>= 1;
}
return res;
}
int main(void)
{
int t;
h[0] = 1;
for(int i=1;i<maxn;i++)
h[i] = (h[i-1]*i)%mod;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d %d",&n,&m);
if(n>m)
swap(n,m);
ll t1 = h[m];
ll t2 = h[n];
ll t3 = h[m-n];
ll t4 = (1LL*t2*t3)%mod;
ll ans = (1LL*t1*qpow(t4,mod-2))%mod;
printf("%I64d\n",ans);
}
return 0;
}