HDU 6114 Chess 【组合数】(2017"百度之星"程序设计大赛 - 初赛(B))

Chess

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


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
 

 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6143 6142 6141 6140 6139 
 

 

Statistic | Submit | Discuss | Note

 

题目链接:

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

题目大意:

  NxM的棋盘放最多的象棋中的车,保证下方的车一定在右侧,求方案数。

题目思路:

  【组合数】

  首先可知必须放min(n,m)个车。

  由于必须靠右侧放,所以等于无序的一个排列。

  其实就是求C(n,m)

  n<m交换n,m

 1 /****************************************************
 2 
 3     Author : Coolxxx
 4     Copyright 2017 by Coolxxx. All rights reserved.
 5     BLOG : http://blog.csdn.net/u010568270
 6 
 7 ****************************************************/
 8 #include<bits/stdc++.h>
 9 #pragma comment(linker,"/STACK:1024000000,1024000000")
10 #define abs(a) ((a)>0?(a):(-(a)))
11 #define lowbit(a) (a&(-a))
12 #define sqr(a) ((a)*(a))
13 #define mem(a,b) memset(a,b,sizeof(a))
14 const double EPS=0.00001;
15 const int J=10;
16 const int MOD=1000000007;
17 const int MAX=0x7f7f7f7f;
18 const double PI=3.14159265358979323;
19 const int N=1004;
20 const int M=1004;
21 using namespace std;
22 typedef long long LL;
23 double anss;
24 LL aans;
25 int cas,cass;
26 int n,m,lll,ans;
27 int c[N][N];
28 void init()
29 {
30     int i,j;
31     c[1][0]=c[1][1]=1;
32     for(i=2;i<N;i++)
33     {
34         c[i][0]=1;
35         for(j=1;j<=i;j++)
36             c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;
37     }
38 }
39 int main()
40 {
41     #ifndef ONLINE_JUDGE
42 //    freopen("1.txt","r",stdin);
43 //    freopen("2.txt","w",stdout);
44     #endif
45     int i,j,k;
46     int x,y,z;
47 //    for(scanf("%d",&cass);cass;cass--)
48     init();
49     for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
50 //    while(~scanf("%d",&n))
51     {
52         scanf("%d%d",&n,&m);
53         if(n<m)swap(n,m);
54         printf("%d\n",c[n][m]);
55     }
56     return 0;
57 }
58 /*
59 //
60 
61 //
62 */
View Code

 

posted @ 2017-08-18 12:50  Cool639zhu  阅读(277)  评论(0编辑  收藏  举报