当前位置:网站首页>Backtracking: Prime Rings
Backtracking: Prime Rings
2022-06-12 13:46:00 【Disobey the law】
#include<iostream>
using namespace std;
int n = 8;
int a[20];// Storing Prime Rings
bool vis[21];
bool isPrime(int x) {
for (int i = 2; i <= x / i; i++) {
if (x % i == 0) return false;
}
return true;
}
void dfs(int beg) {
if (beg == n && isPrime(a[0] + a[n - 1])){
for (int i = 0; i < n; i++)
cout << a[i]<<" ";
cout << endl;
return;
}
for (int j = 1; j <= n; j++)
if (!vis[j] && isPrime(j + a[beg - 1])) {
a[beg] = j;
vis[j] = true;
dfs(beg + 1);
vis[j] = false;
}
}
int main()
{
a[0] = 1;//1 Set the position , It's a ring. , All the first elements do not affect the overall trend
vis[1] = true;
dfs(1);
}
边栏推荐
- 1001:Hello,World
- 聊聊MySQL的10大经典错误
- 事件的传递和响应以及使用实例
- 1414: [17noip popularization group] score
- C language implementation of string and memory library functions
- Implementing pytorch style deep learning framework similartorch with numpy
- Convert the string to hexadecimal string and display it
- Application of list and Dict
- 2063: [example 1.4] cattle eat grass
- 2021-05-28
猜你喜欢

Multi source BFS problem template (with questions)

When the byte jumps, the Chinese 996 is output in the United States

一种快速创建测试窗口的方法

Talk about the top 10 classic MySQL errors

Script import CDN link prompt net:: err_ FILE_ NOT_ Found problem

Wechat web developer tools tutorial, web development issues

Title: Yanghui triangle

Go zero micro Service Practice Series (II. Service splitting)
![[semidrive source code analysis] [x9 chip startup process] 25 - Introduction to mailbox inter core communication mechanism (code analysis) rpmsg-ipcc RTOS & QNX](/img/90/98faa5856fbc55ff7fda4a3adb3650.png)
[semidrive source code analysis] [x9 chip startup process] 25 - Introduction to mailbox inter core communication mechanism (code analysis) rpmsg-ipcc RTOS & QNX

Hash tables, sets, maps, trees, heaps, and graphs
随机推荐
Codeforces 1637 A. sorting parts - simple thinking
How to solve the problem of data table query error when SQLite writes the registration function?
Automatic Generation of Visual-Textual Presentation Layout
【SemiDrive源码分析】【X9芯片启动流程】25 - MailBox 核间通信机制介绍(代码分析篇)之 RPMSG-IPCC RTOS & QNX篇
Explanation of static and extern keywords
MySQL 查询 limit 1000,10 和 limit 10 速度一样快吗? 深度分页如何破解
Transmission and response of events and use cases
Teach you how to create SSM project structure in idea
Introduction to color coding format
import torch_ Geometric loads some common datasets
Innovation training (XI) summary of some bugs in the development process
C language structure
数据类型转换和条件控制语句
2067: [example 2.5] circle
C language implementation of string and memory library functions
[wustctf2020] selfie score query -1
Informatics Olympiad all in one 2059: [example 3.11] buy a pen
Realization of Joseph Ring with one-way ring linked list
Cdeforces 1638 C. inversion graph - simple thinking
jupyternotebook有汉字数据库吗。在深度学习中可以识别手写中文吗