标签:hdu closed 一个人 nbsp iostream lap 有一个 mod time
错排 / 全部排列 即为答案
关于错排的求解:
f(n) = (n-1) * (f(n-1) + f(n-2))
边界 f(1) = 1 , f(2 ) = 1
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <bitset> using namespace std; typedef long long LL; #define MOD 20090126 LL fac[25],f[25]; int T; int main(){ // freopen("test.in","r",stdin); cin >> T; f[1] = 0; f[2] = 1; fac[1] = 1; fac[2] = 2; for (int i=3;i<=20;i++){ fac[i] = fac[i-1] * i; f[i] = (i-1) * (f[i-1] + f[i-2]); } for (int times = 1; times <= T; times ++){ int n; cin >> n; printf("%.2lf%%\n", f[n] * 1.0 / fac[n] * 100); } return 0; }
标签:hdu closed 一个人 nbsp iostream lap 有一个 mod time
原文地址:http://www.cnblogs.com/ToTOrz/p/7390317.html