记录编号 |
385049 |
评测结果 |
AAAAA |
题目名称 |
[HAOI 2004模拟]数列问题 |
最终得分 |
100 |
用户昵称 |
Marshmello |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.030 s |
提交时间 |
2017-03-19 21:42:55 |
内存使用 |
0.29 MiB |
显示代码纯文本
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 15+5;
FILE *fin, *fout;
const int pri[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 };
bool vis[maxn];
int ans = 0, n, d[maxn];
void print_d() {
for(int i = 1; i <= n; i++)
fprintf(fout, "%d ", d[i]);
}
bool check(int a) {
int p = lower_bound(pri, pri+15, a)-pri;
if(pri[p] == a) return true;
else return false;
}
void dfs(int dep) {
if(dep == n+1) { print_d(); fprintf(fout, "\n"); ans++; return; }
for(int i = 1; i <= n; i++) if(!vis[i]) {
if(dep == 1) { vis[i] = true; d[dep] = i; dfs(dep+1); vis[i] = false; }
else if(check(d[dep-1]+i)) { vis[i] = true; d[dep] = i; dfs(dep+1); vis[i] = false; }
}
}
int main() {
fin = fopen("dfs3.in", "r");
fout = fopen("dfs3.out", "w");
// fout = stdout;
fscanf(fin, "%d", &n);
dfs(1);
fprintf(fout, "%d", ans);
return 0;
}