Chess
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 148 Accepted Submission (s): 110
Problem Description is a pawn in Chinese chess that can attack pieces that are not blocked by other pieces in the same row or column. One day, the small degree on the board to put up a lot of cars ... He wanted to know the number of scenarios in which the largest number of cars in a rectangular checkerboard with a total of nxm points made it non-attacking. He went through the thought and came to an answer. But he is still not satisfied, want to add a condition: for any car A, if there is another car B above it (car B is less than car a), then car a must be on the right side of car B (car a column number is larger than car B).
Now it's time to ask you what the number of scenarios is to meet the requirements.
Input first line A positive integer t representing the number of data groups.
For each set of data: One row, two positive integers N and M (n<=1000,m<=1000).
Output is a row for each set of data, representing the scheme number modulo 1000000007 (1e9+7).
Sample Input
1 1 1
Sample Output
1
Source 2017 "Baidu Star" program design contest-Preliminary round (B)
————————————————————————————————— idea: Combinatorial mathematical calculation
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <complex >
#include <vector>
#include <bitset>
#include <stack>
#include <queue >
#include <map>
#include <set>
using namespace std;
#define _inf 0x3f3f3f3f
#define _inf 1e99
#define _PI acos ( -1.0)
#define _EPS 1e-8
#define LL Long Lo ng
Const LL mod=1e9+7;
LL c[1005][1005];
void init ()
{
c[0][0] = 1;
for (int i = 1; i < 1004; i++)
{
c[i][0] = c[i][i] = 1;
for (int j = 1; j < I; j + +)
c[i][j] = (C[i-1][j-1] + c[i-1][j])% mod;
}
}
int main ()
{
int n,m,t;
Init ();
For (scanf ("%d", &t); t--;)
{
scanf ("%d%d", &n,&m);
if (n<m)
swap (n,m);
int t = n-m;
printf ("%lld\n", C[n][t]);
}
return 0;
}