HDU 6114 Chess 【組合數】(2017"百度之星"程序設計大賽 - 初賽(B))
阿新 • • 發佈:2017-08-18
code ace ide memory stdin splay des cor c++
現在要問問你,滿足要求的方案數是多少。
Input
第一行一個正整數T,表示數據組數。
對於每組數據:一行,兩個正整數N和M(N<=1000,M<=1000)。
Statistic | Submit | Discuss | Note
Chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 513 Accepted Submission(s): 319
現在要問問你,滿足要求的方案數是多少。
對於每組數據:一行,兩個正整數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
題目鏈接:
http://acm.hdu.edu.cn/showproblem.php?pid=6114
題目大意:
NxM的棋盤放最多的象棋中的車,保證下方的車一定在右側,求方案數。
題目思路:
【組合數】
首先可知必須放min(n,m)個車。
由於必須靠右側放,所以等於無序的一個排列。
其實就是求C(n,m)
n<m交換n,m
1 /**************************************************** 2 3 Author : CoolxxxView Code4 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 */
HDU 6114 Chess 【組合數】(2017"百度之星"程序設計大賽 - 初賽(B))