hdu 6114/2017百度之星预赛B Chess(找规律)

来源:互联网 发布:程序员需求量 编辑:程序博客网 时间:2024/06/05 06:18

Chess

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


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
11 1
 

Sample Output
1
 

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

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6119 6118 6117 6116 6115 
 

Statistic | Submit | Discuss | Note
画几个方格找规律,发现是C(n,m)。递推求组合数即可。

#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <string.h>#include <map>#include <set>#include <queue>#include <deque>#include <list>#include <bitset>#include <stack>#include <stdlib.h>#define lowbit(x) (x&-x)#define e exp(1.0)const int mod=1e9+7;//ios::sync_with_stdio(false);//    auto start = clock();//    cout << (clock() - start) / (double)CLOCKS_PER_SEC;typedef long long ll;typedef long long LL;using namespace std;ll C[1005][1005];int main(){    C[1][0] = C[1][1] = 1;    for (int i = 2; i < 1005; i++)    {        C[i][0] = 1;        for (int j = 1; j < 1005; j++)            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1])%mod;    }    int T;    cin>>T;    while(T--)    {        int n,m;        cin>>n>>m;        if(n<m)            swap(n,m);        cout<<C[n][m]%mod<<endl;    }    return 0;}