Posted on 2010-12-07 21:12
王之昊 阅读(287)
评论(0) 编辑 收藏 引用 所属分类:
sgu
sgu 221是互不攻击的象,这次是互不攻击的车。这个比较简单,如果k > n直接无解,否则答案为C( n, k )*C( n, k )*( k! )
accept code
1
2 import java.util.Scanner;
3 import java.util.*;
4 import java.math.BigInteger;
5
6 class rook{
7 int n, k;
8
9 long [][]C;
10
11 rook(int _n, int _k){
12 n = _n;
13 k = _k;
14 }
15
16 long fac(int k){
17 if(k==0)
18 return 1;
19 else
20 return k * fac(k-1);
21 }
22
23 long count(){
24
25 C = new long[n+1][n+1];
26
27 for(int i = 0; i <= n; i++){
28 C[i][0] = C[i][i] = 1;
29 for(int j = 1; j < i; j++)
30 C[i][j] = C[i-1][j-1] + C[i-1][j];
31 }
32
33 if(n < k){
34 return 0;
35 }
36 else{
37 long kk = C[n][k];
38 return kk * kk * fac( k );
39 }
40 }
41 }
42
43 public class Solution{
44 public static void main(String[] args)throws Exception{
45 Scanner sc = new Scanner(System.in);
46
47 rook r = new rook( sc.nextInt(), sc.nextInt() );
48
49 System.out.println( r.count() );
50 }
51 }