This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.
#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;