hdu 1016 Prime Ring Problem(dfs)
来源:互联网 发布:会编程可以在家工作吗 编辑:程序博客网 时间:2024/05/21 07:54
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016
错了不低于五遍才发现输出的格式错了
很明显的深搜题目
#include <stdio.h>#include <string.h>int prime[12] = {2,3,5,7,11,13,17,19,23,29,31,37};//打表素数int isPrime(int p)//判断素数{ int i; for(i = 0; i < 12;i++) if(p == prime[i]) return 1; return 0;}int n,book[21],record[21];void DFS(int step){ int i; if(step == n+1 && isPrime(record[step-1]+1)) { for(i = 1; i <= n; ++i) { printf("%d",record[i]); if(i != n) printf(" "); } printf("\n"); return ; } for(i = 2; i <= n; ++i) if(book[i] == 0 && isPrime(i+record[step-1])) { record[step] = i; book[i] = 1;//把用过的标记上 DFS(step+1); book[i] = 0;//取消标记,使重新求串时不会受到干扰 } return ;}int main(){ int time = 0; record[1] = 1; while(scanf("%d",&n) != EOF) { ++time; printf("Case %d:\n",time); memset(book,0,sizeof(book)); DFS(2);//深搜 printf("\n"); } return 0;}
0 0
- 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 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 1016 Prime Ring Problem (dfs)
- HDU 1016 Prime Ring Problem (DFS)
- 使用ViewPager+Fragment实现选项卡切换效果
- Hibernate单向关联比较
- Android UI效果之绘图篇(一)
- Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.Entity
- yii 查询构建器
- hdu 1016 Prime Ring Problem(dfs)
- CentOS7系统的root密码丢失后如何重设
- 019.php函数变量
- atitit.React 优缺点 相比angular react是最靠谱的web ui组件化方案了
- Machine Learning Logistic Regression and Newton's Method Andrew Ng 课程练习 Matlab Script 详细解析
- iOS网络编请求响应之URL结构
- Servlet技术
- Java NIO系列教程(二) Channel
- samba服务器搭建