题目链接: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(素数环问题——递归算法)的更多相关文章

  1. Hdu 1016 Prime Ring Problem (素数环经典dfs)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. HDOJ 1016 Prime Ring Problem素数环【深搜】

    Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, -, ...

  3. Prime is problem - 素数环问题

    题目描述: A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each ...

  4. Prime Ring Problem + nyoj 素数环 + Oil Deposits + Red and Black

    Prime Ring Problem Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) ...

  5. HDU 1016 Prime Ring Problem(素数环问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...

  6. hdu1016 Prime Ring Problem【素数环问题(经典dfs)】

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. [HDU 1016]--Prime Ring Problem(回溯)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...

  8. UVA524 素数环 Prime Ring Problem

    题目OJ地址: https://www.luogu.org/problemnew/show/UVA524 hdu oj 1016:  https://vjudge.net/problem/HDU-10 ...

  9. 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 ...

随机推荐

  1. js 闭包实例

    var db = (function() { // 创建一个隐藏的object, 这个object持有一些数据 // 从外部是不能访问这个object的 var data = {}; // 创建一个函 ...

  2. Dependency Scopes(maven)

    Dependency scope 是用来限制Dependency的作用范围的, 影响maven项目在各个生命周期时导入的package的状态. 自从2.0.9后,新增了1种,现在有了6种scope: ...

  3. 纯js实现最简单的文件上传(后台使用MultipartFile)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. SharePoint 2013 将HTML文件转换为母版页

    内容中包含 base64string 图片造成字符过多,拒绝显示

  5. Linux下安装或升级Python 2.7

    1.准备编译环境gcc 2.去官网下载要安装的对应版本的python的源代码 下载地址:https://www.python.org/downloads/source/ 你可以选择你要下载的版本,用w ...

  6. PHP 使用memcached

    1.添加扩展包 php_memcache.dll 2.在PHP.INI添加 extension=php_memcache.dll 3.程序 <?php //创建一个mem对象实例 $mem=ne ...

  7. 【2018年12月05日】滚动市盈率PE最低排名

    深康佳A(SZ000016) - 滚动市盈率PE:1.69 - 滚动市净率PB:1.13 - 滚动年化股息收益率:4.31% - 消费电子产品 - 深康佳A(SZ000016)的历史市盈率走势图 新钢 ...

  8. alsa wav

    wav_parser.h文件: //File : wav_parser.h //Author : Loon <sepnic@gmail.com> #ifndef __WAV_PARSER_ ...

  9. PHP 免费获取手机号码归属地

    一.淘宝网API API地址: http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443 参数: tel:手机号码 返回 ...

  10. 【安全开发】python安全编码规范

    申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...