题目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 ...
随机推荐
- 【Php】数组遍历,foreach, each, trim()
<?php $iplist = "122.224.251.154|192.168.2.138|192.168.2.12"; echo $_SERVER['REMOTE_ADD ...
- Android Material Design控件学习(二)——NavigationView的学习和使用
前言 上次我们学习了TabLayout的用法,今天我们继续学习MaterialDesign(简称MD)控件--NavigationView. 正如其名,NavigationView,导航View.一般 ...
- jquery获取data-xxx自定义属性的值遇到的问题
直接用jquery的 data("name") 获取 data-name的值有问题,获取的只是最初的值,即使后边改变也不会变,所以还是要用attr("data-name& ...
- vue的iview列表table render函数设置DOM属性值的方法
{ title: '负责人社保照片', key: 'leaderIdNumber', render: (h, params) => { return h('img',{domProps:{ sr ...
- Unity3d开发“类三消”游戏
新建一个Project,导入图片素材和声音文件,把图片的Texture Type都修改为Sprite(2D and UI)[1].新建一个命名为Background的GameObject,为之添加背景 ...
- 在AD的环境下,更改计算机名导致TFS,无法连接解决办法
D:\vs2015>tf workspaces /collection:http://10.1.0.104:8080/tfs/dahua.adrms /updateComputerName:WI ...
- Linux 查看磁盘分区、文件系统、磁盘的使用情况相关的命令和工具介绍
https://www.cnblogs.com/alexyuyu/articles/3454907.html
- 【代码审计】ThinkSNS_V4 任意文件下载漏洞分析
0x00 环境准备 ThinkSNS官网:http://www.thinksns.com 网站源码版本:ThinkSNS V4 更新时间:2017-09-13 程序源码下载:http://www ...
- [ZZ]c++ cout 格式化输出浮点数、整数及格式化方法
C语言里可以用printf(),%f来实现浮点数的格式化输出,用cout呢...?下面的方法是在网上找到的,如果各位有别的办法谢谢留下... iomanip.h是I/O流控制头文件,就像C里面的格式化 ...
- SpringBoot(九)-- SpringBoot JDBC
1.属性配置文件(application.properties) # type 可以修改连接池类型,默认采用Tomcat的连接池 # spring.datasource.type=com.alibab ...