'commit'
This commit is contained in:
37
TangDou/Mkx/HDU2048_DFS.cpp
Normal file
37
TangDou/Mkx/HDU2048_DFS.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user