HDU6114-Chess

Chess

                                                                       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                                                                                                 Total Submission(s): 358    Accepted Submission(s): 248


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
 


解题思路:其实就是算从n个位置中挑出m个位置有几种挑法


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;

int n, m;
LL x[1009][1009];

void C()
{
    x[0][0] = 1;
    for (int i = 1; i < 1009; i++)
    {
        x[i][0] = x[i][i] = 1;
        for (int j = 1; j < i; j++)
            x[i][j] = (x[i - 1][j - 1] + x[i - 1][j]) % mod;
    }
}

int main()
{
    C();
    int t;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d", &n, &m);
        if (n > m) swap(n, m);
        int ma = max(n, m), k = abs(n - m);
        printf("%lld\n", x[ma][k]);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值