题目链接: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. C# 抓取网页的img src带参数的图片链接,并下载

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. yii2 使用阿里大鱼短信

    1.首先申请阿里账号 2.开通短信服务 3.短信签名 4.添加模板 以上4步是前期工作 -------------------------------------------------------- ...

  3. CALayer: autoresizingMask

    UIView 可以设定 autoresizingMask,当它的 superView 尺寸改变时,适应何种变化. 不过 CALayer 却没有这个属性,如和做到让 CALayer 和 UIView 一 ...

  4. js中的方法调用

    <script> var m = {com: { sao: {citi:{}}}}; m.com.sao.citi.init = new function() { this.name = ...

  5. 安装PHP5 PHP7

    安装 PHP5 PHP官网www.php.net • 当前主流版本为5./7.1 • cd /usr/local/src/ • wget http://cn2.php.net/distribution ...

  6. $(this).bind("change",itemno_change);

    如果是onchange 会出错,超过3个可能就无效.

  7. Single Pattern(单例模式)

    单例模式是一种常用的软件设计模式.通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问,从而方便对实例个数的控制并节约系统资源.如果希望在系统中某个类的实例只能存在一个,单例模式是最好的 ...

  8. [Object Tracking] Identify and Track Specific Object

    Abstract—Augmented Reality (AR) has become increasingly popular in recent years and it has a widespr ...

  9. okHttp3自用封装

    okHttp都已经出到3.2.0了,现在才开始要用到它,感觉自己好low~~ 根据平时自己的习惯,还是自己做一下封装,让代码撸起来更加顺畅一点! okhttp-3.2.0和okio-1.7.0就不多说 ...

  10. C#中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别

    // 获取程序的基目录. System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径. System.Diagnostics.Process.G ...