You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
756 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
typedef long long LL;
// TLE 超时,看来,还是递推更安全些
int n;
LL res, sum;
int st[N];
void dfs(int u) {
if (u == n + 1) {
res++;
return;
}
for (int i = 1; i <= n; i++)
if (!st[i] && u != i) {
st[i] = true;
dfs(u + 1);
st[i] = false;
}
}
int main() {
int m;
scanf("%d", &m);
while (m--) {
scanf("%d", &n);
memset(st, 0, sizeof st);
sum = 1;
dfs(1);
//总次数
for (int i = 1; i <= n; i++) sum = sum * i;
//比率
printf("%.2lf%%\n", (double)res / sum * 100);
}
return 0;
}