#include <iostream> using namespace std; long long a[21]; long long b[21]; int main() { int C; a[1] = 0; a[2] = 1; b[1] = 1; b[2] = 2; for (long i = 3; i <= 20; i++) { a[i] = (i - 1)*(a[i - 1] + a[i - 2]); b[i] = i*b[i - 1]; } while (cin >> C) { while (C--) { int n; cin >> n; printf("%.2lf", 100.0*a[n] / b[n]); cout << "%" << endl; } } }
1--nphp
第一個位置是2--n,n-1種ios
第二個位置是1,剩餘數排列 a(n-2)spa
第二個位置不是1,剩餘數排列a(n-1)code
a(n) = (n-1)*(a(n-2) + a(n-1))blog
http://acm.hdu.edu.cn/showproblem.php?pid=2048ci