• HDU 2049 考新郎


    错排列问题,依然裸题。。。

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <cctype>
     6 
     7 using namespace std;
     8 
     9 inline void read(long long &x)
    10 {
    11     int k = 1; x = 0;
    12     char c = getchar();
    13     while (!isdigit(c))
    14         if (c == '-') k = - 1, c = getchar();
    15         else c = getchar();
    16     while (isdigit(c))
    17         x = (x << 1) + (x << 3) + (c ^ 48),
    18         c = getchar();
    19     x *= k;
    20 }
    21 
    22 long long T, n, m, dp[55], mul[55];
    23 
    24 int main()
    25 {
    26     read(T), mul[0] = 1;
    27     for (int i = 1; i <= 30; ++i) 
    28         mul[i] = mul[i - 1] * i;
    29     for (int plk = 1; plk <= T; ++plk)
    30     {
    31         read(n), read(m);
    32         memset(dp, 0, sizeof(dp));
    33         dp[0] = 0, dp[1] = 0, dp[2] = 1;
    34         for (int i = 3; i <= n; ++i)
    35             dp[i] = (i - 1) * (dp[i - 1] + dp[i - 2]); 
    36         printf("%lld
    ", dp[m] * (mul[n] / (mul[m] * mul[n - m])));
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    11111
    JavaScript基础
    CSS使用
    CSS 基本
    前端之HTML
    Python 迭代器和生成器
    Python day11
    Python 函数
    第十七篇:django基础(二)
    第十六篇:django基础
  • 原文地址:https://www.cnblogs.com/yanyiming10243247/p/10112492.html
Copyright © 2020-2023  润新知