题目1459:Prime ring problem(素数环问题——递归算法)
题目链接:http://ac.jobdu.com/problem.php?pid=1459
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
//
// 1459 Prime ring problem.cpp
// Jobdu
//
// Created by PengFei_Zheng on 23/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#define PRIME 13
#define MAX_SIZE 21
using namespace std; int n;
int ans[MAX_SIZE];
bool used[MAX_SIZE]; int prime[]={,,,,,,,,,,,,};
bool judge(int x){
for(int i = ; i < PRIME ; i++){
if(prime[i]==x)
return true;
}
return false;
} void check(){
if(!judge(ans[n]+ans[])) return;
for(int i = ; i <= n ; i++){
if(i!=) printf(" ");
printf("%d",ans[i]);
}
printf("\n");
} void DFS(int num){
if(num>){
if(!judge(ans[num] + ans[num - ])) return;
}
if(num==n){
check();
return;
}
for(int i = ; i <= n ; i++){
if(!used[i]){
used[i] = true;
ans[num+] = i;
DFS(num+);
used[i] = false;
}
}
} int main(){
int kase = ;
while(scanf("%d",&n)!=EOF){
kase++;
memset(used,false,sizeof(used));
ans[] = ;
used[]=true;
printf("Case %d:\n",kase);
DFS();
printf("\n");
}
return ;
}
/**************************************************************
Problem: 1459
User: zpfbuaa
Language: C++
Result: Accepted
Time:590 ms
Memory:1520 kb
****************************************************************/
题目1459:Prime ring problem(素数环问题——递归算法)的更多相关文章
- Hdu 1016 Prime Ring Problem (素数环经典dfs)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDOJ 1016 Prime Ring Problem素数环【深搜】
Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, -, ...
- Prime is problem - 素数环问题
题目描述: A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each ...
- Prime Ring Problem + nyoj 素数环 + Oil Deposits + Red and Black
Prime Ring Problem Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- HDU 1016 Prime Ring Problem(素数环问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- hdu1016 Prime Ring Problem【素数环问题(经典dfs)】
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- [HDU 1016]--Prime Ring Problem(回溯)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- UVA524 素数环 Prime Ring Problem
题目OJ地址: https://www.luogu.org/problemnew/show/UVA524 hdu oj 1016: https://vjudge.net/problem/HDU-10 ...
- Hdu1016 Prime Ring Problem(DFS) 2016-05-06 14:27 329人阅读 评论(0) 收藏
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- NHibernate Isession管理
一个Session foreach (var item in favoriteId) { if (!string.IsNullOrEmpty(item)) { var favorite = _sess ...
- 使用 mysql_use_result 还是使用 mysql_store_result?
From: http://my.oschina.net/moooofly/blog/186456 本文整理了关于“使用 mysql_use_result 还是 mysql_store_result”的 ...
- iOS : 用 InterfaceBuilder 开始一个项目
1.创建一个 xib 文件 : Main_iPhone.xib 更改 File's Owner 的 Class 为 UIApplication; 添加 1 个 Window .1 个 Object . ...
- centos7 Minimal安装没有ifconfig
centos7 Minimal 安装后 ip addr 系统的网卡没有分配IP地址 网卡为ens33 cd /etc/sysconfig/network-scripts vi ifcfg-ens33 ...
- 怎么安装ABBYY FineReader
ABBYY FineReader是市场领先的文字识别(OCR)软件,可快速方便地将扫描纸质文档.PDF文件和数码相机的图像转换成可编辑.可搜索信息,ABBYY FineReader 12是目前最新版本 ...
- Phpcms V9单页添加自定义字段
说起文章自定义自段,大家都会想到 wordpress 的自定义字段,确实 wordpress 系统很强大,字段可以很灵活的在后台进行添加与更新,并能够很好的在前台进行调用,对于这点 phpcms v9 ...
- Jsoup(一)-- HelloWorld
1.简介 jsoup 是一款Java 的HTML解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuery的操作方法来取出和操作数据. ...
- NFS 配置文件
NFS 配置文件是 /etc/exports,内容如下: [root@localhost ~]# cat /etc/exports /data 192.168.216.129/32(rw,sync,a ...
- Hadoop核心架构HDFS+MapReduce+Hbase+Hive内部机理详解
转自:http://blog.csdn.net/iamdll/article/details/20998035 分类: 分布式 2014-03-11 10:31 156人阅读 评论(0) 收藏 举报 ...
- Failed to resolve
一: 把//classpath 'com.android.tools.build:gradle:2.2.2'改成classpath 'com.android.tools.build:gradle:3. ...