题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1005

纸上画一下,找了一下规律,Ank*Cnk.

 1 //#pragma comment(linker, "/STACK:102400000, 102400000")
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <cstdio>
 7 #include <vector>
 8 #include <cmath>
 9 #include <ctime>
10 #include <list>
11 #include <set>
12 #include <map>
13 using namespace std;
14 typedef long long LL;
15 typedef pair <int, int> P;
16 const int N = 1e5 + 5;
17 
18 LL Anm(LL n, LL m) {
19     LL ans = 1;
20     for(LL i = n; i >= n - m + 1; --i) {
21         ans = ans * i;
22     }
23     return ans;
24 }
25 
26 int main()
27 {
28     int t;
29     LL n, k;
30     scanf("%d", &t);
31     for(int ca = 1; ca <= t; ++ca) {
32         scanf("%lld %lld", &n, &k);
33         printf("Case %d: ", ca);
34         if(k > n) {
35             printf("0\n");
36             continue;
37         }
38         LL ans = Anm(n, k);
39         LL temp = ans;
40         for(LL i = k; i >= 2; --i) {
41             temp /= i;
42         }
43         printf("%lld\n", ans * temp);
44     }
45     return 0;
46 }

 

相关文章:

  • 2022-12-23
  • 2021-06-09
  • 2022-01-29
  • 2021-10-29
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
相关资源
相似解决方案