Chess 模拟

链接:http://acm.hdu.edu.cn/showproblem.php?pid=6114

Problem Description
車是中国象棋中的一种棋子,它能攻击同一行或同一列中没有其他棋子阻隔的棋子。一天,小度在棋盘上摆起了许多車……他想知道,在一共N×M个点的矩形棋盘中摆最多个数的車使其互不攻击的方案数。他经过思考,得出了答案。但他仍不满足,想增加一个条件:对于任何一个車A,如果有其他一个車B在它的上方(車B行号小于車A),那么車A必须在車B的右边(車A列号大于車B)。

现在要问问你,满足要求的方案数是多少。
 

Input
第一行一个正整数T,表示数据组数。

对于每组数据:一行,两个正整数N和M(N<=1000,M<=1000)。
 

Output
对于每组数据输出一行,代表方案数模1000000007(1e9+7)。
 

Sample Input
1
1 1
 

Sample Output
1
 

Source
2017"百度之星"程序设计大赛 - 初赛(B)
题干

就是简单的组合数。

#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define  MOD 1000000007
#define LL long long  
int n,m,t;
LL f[1100][1100];
int main()
{
    scanf("%d",&t);
    f[0][0]=1;
    for(int i=1;i<=1009;i++)
    {
        f[i][0]=1;
        for(int j=1;j<i;j++)    
            f[i][j]=(f[i-1][j-1]+f[i-1][j])%MOD;
        f[i][i]=1;
    }
    while(t--)
    {
        scanf("%d%d",&n,&m);
        if(n>m)    {int temp=m; m=n; n=temp;}
        if(m==1||n==1)
        {
            cout<<1<<endl;
            continue;
        }
        cout<<f[m][n]<<endl;
    }
    return 0;
}
代码
原文地址:https://www.cnblogs.com/CLGYPYJ/p/7388347.html