当前位置:网站首页>(dfs) acwing 842. Arrange numbers
(dfs) acwing 842. Arrange numbers
2022-06-13 09:24:00 【Age worry】
842. Arrange numbers
Topic link https://www.acwing.com/problem/content/844/
subject :
Method 1 :dfs
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
bool vis[10];
int a[10];
int n;
void dfs(int u,int id){
a[++id]=u;
if(id==n){
for(int i=1;i<=n;i++){
printf("%d ",a[i]);
}
printf("\n");
return ;
}
vis[u]=1;
for(int i=1;i<=n;i++){
if(!vis[i]) dfs(i,id);
}
vis[u]=0;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
memset(vis,0,sizeof vis);
dfs(i,0);
}
return 0;
}
next_permutation Method https://blog.csdn.net/weixin_46028214/article/details/115432647
边栏推荐
- LeetCode 322. 零钱兑换
- Necessary and sufficient conditions for diagonalization of 20211115 matrix; The full rank matrix does not necessarily have n linearly independent eigenvectors; Symmetric matrices must be diagonalized
- 攻防世界-PWN-shell
- C language: deep understanding of pointers and arrays
- Collection of articles on virtualization and cloud computing
- LeetCode 5270. Minimum path cost in grid (dynamic programming)
- Yolov5 face learning notes
- 20211104 why are the traces of similar matrices the same
- Redis fuzzy query batch deletion
- final 原理
猜你喜欢

BGP Federation +community

Longadder of the source code of JUC atomic accumulator

Jenkins accédant à l'authentification de l'utilisateur openldap

C language: Simulated Implementation of library function strcpy

Simulink variant model and variant subsystem usage

Alibaba senior experts analyze the standard design of protocol

Class loading overview

Storage mode of drawings

Routing - static routing

20220524 how to install coppeliasim to disk D
随机推荐
C language 7-13 day K candle chart (15 points)
20211115 any n-order square matrix is similar to triangular matrix (upper triangle or lower triangle)
LeetCode 5270. 网格中的最小路径代价(动态规划)
Collection of articles on virtualization and cloud computing
final 原理
Immutability of shared model
Z字形变换
JUC原子整数
LeetCode 343. 整数拆分
JUC 原子累加器 源码之 LongAdder
Lecture par lots de tous les fichiers vocaux sous le dossier
攻防世界-PWN-shell
20211018 some special matrices
JUC Unsafe
Solov2 source code analysis
LeetCode 322. 零钱兑换
IP address introduction
[most comprehensive and detailed explanation] detailed explanation of knapsack problem
C language: sanziqi
C language: minesweeping