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\n", dp[m] * (mul[n] / (mul[m] * mul[n - m]))); 37 } 38 return 0; 39 }