1. 程式人生 > >HDU 6114 Chess 【組合數】(2017"百度之星"程序設計大賽 - 初賽(B))

HDU 6114 Chess 【組合數】(2017"百度之星"程序設計大賽 - 初賽(B))

code ace ide memory stdin splay des cor c++

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 2017"百度之星"程序設計大賽 - 初賽(B)

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

HDU 6114 Chess 【組合數】(2017"百度之星"程序設計大賽 - 初賽(B))