HDU 1016 - Prime Ring Problem [简单DFS]
来源:互联网 发布:淘宝哪里取消申请退款 编辑:程序博客网 时间:2024/06/05 20:28
不想说这题有多么水了,最简单的DFS题了,但是!我花了N天在杭电用G++交了20多遍一直超时,最后改C++交过了!!
这是什么情况!!无语了!!
#define _CRT_SECURE_NO_WARNINGS#include <cstdio>#include <cstring>#include <cstdlib>const int maxn = 1024;bool checked[maxn] = { 1, 1 };int pri[maxn], tot = 0;int n, res[22], kase = 0, vis[22];void init(){ for (int i = 2; i < maxn; ++i){ if (!checked[i]) pri[tot++] = i; for (int j = 0; j < tot && pri[j] * i < maxn; ++j){ checked[pri[j] * i] = 1; if (!(i % pri[j])) break; } }}void DFS(const int d){ if (d == n){ if (!checked[1 + res[d - 1]]){ for (int i = 0; i < n; ++i) printf("%d%c", res[i], i == n - 1 ? '\n' : ' '); } return; } for (int i = 2; i <= n; ++i){ if (!vis[i] && !checked[i + res[d - 1]]){ vis[i] = 1; res[d] = i; DFS(d + 1); vis[i] = 0; } }}int main(){ init(); while (~scanf("%d", &n)) { printf("Case %d:\n", ++kase); memset(vis, 0, sizeof(vis)); res[0] = 1; vis[1] = 1; DFS(1); printf("\n"); } return 0;}
0 0
- HDU 1016Prime Ring Problem简单dfs
- HDU 1016 Prime Ring Problem 简单DFS
- HDU 1016 - Prime Ring Problem [简单DFS]
- Prime Ring Problem hdu 1016 dfs
- Hdu-1016 Prime Ring Problem【DFS】
- HDU 1016(Prime Ring Problem)DFS
- hdu 1016 Prime Ring Problem dfs搜索
- hdu 1016 Prime Ring Problem (dfs)
- hdu 1016 Prime Ring Problem(DFS)
- HDU 1016 Prime Ring Problem【DFS】
- hdu 1016 Prime Ring Problem(DFS)
- HDU 1016 Prime Ring Problem (DFS)
- HDU 1016Prime Ring Problem(dfs)
- hdu 1016 Prime Ring Problem (dfs)
- hdu 1016 Prime Ring Problem dfs
- Hdu 1016 Prime Ring Problem DFS搜索
- HDU 1016 Prime Ring Problem(DFS)
- hdu 1016Prime Ring Problem dfs
- 多线程与多进程的对比
- 网站分析与优化
- 3.17
- Codeforces #257B Jzzhu and Sequences(矩阵快速幂)
- 程序猿的日常-5
- HDU 1016 - Prime Ring Problem [简单DFS]
- Letter Combinations of a Phone Number
- 《AngularJS权威教程》
- F - Flowers
- Android学习笔记の五
- 15 Wallpaper 之OnTouch OnIntercept dispatch事件机制
- Raising Modulo Numbers (poj 1995 快速幂水题)
- c和c++的一些训练题(9)(学生成绩管理系统)
- HDU 4549 M斐波那契数列(矩阵快速幂)