当前位置:网站首页>[summer daily question] Luogu p1706 full ranking question
[summer daily question] Luogu p1706 full ranking question
2022-07-25 01:21:00 【AC_ Dragon】
Topic link :P1706 The total permutation problem - Luogu | New ecology of computer science education (luogu.com.cn)
Title Description
Output natural numbers in dictionary order 1 To n All the non repetitive permutations , namely n The whole arrangement , It is required that no duplicate number is allowed in any number sequence generated .
Input format
An integer n.
Output format
from 1 ~ n A sequence of all the numbers that do not repeat , One sequence per line .
Keep every number 5 Field width .
Examples #1
The sample input #1
3Sample output #1
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1Tips
1 <= n <= 9.
AC code 1:(DFS)
#include<iostream>
using namespace std;
int n;
int a[10],book[10];
void dfs(int step)
{
if(step==n+1)
{
for(int i=1;i<=n;i++)
printf("%5d",a[i]);
puts("");
return ;
}
for(int i=1;i<=n;i++)
{
if(book[i]==0)
{
a[step]=i;
book[i]=1;
dfs(step+1);
book[i]=0;
}
}
return ;
}
int main()
{
cin>>n;
dfs(1);
return 0;
}AC code 2:(STL-next_permutation)
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
string s="123456789";
do{
for(int i=0;i<n;i++)
printf("%5c",s[i]);
puts("");
}while(next_permutation(s.begin(),s.begin()+n));
}边栏推荐
- Password input box and coupon and custom soft keyboard
- Amd epyc 9654 Genoa CPU cache test exposure L1 bandwidth up to 30tb/s
- How to obtain workers' coats and helmets in stray? How to obtain workers' helmets
- [28. Maximum XOR pair]
- "Usaco2006nov" corn fields solution
- The IPO of Tuba rabbit was terminated: the annual profit fell by 33%, and Jingwei Sequoia was the shareholder
- Unity slider slider development
- Prosci 14-3-3 (phosphate ser58) antibody instructions
- VC hesitates to invest in Henan
- Three possible scenarios for SAP Spartacus server-side rendering
猜你喜欢

Visual studio code installation package download slow & Installation & environment configuration & new one-stop explanation

This visual is not connected to the presentationsource.

What is the root password of MySQL initial installation

Introduction to thread pool

The current situation of the industry is disappointing. After working, I returned to UC Berkeley to study for a doctoral degree

Kernel structure and design

Harbor installation

How to empty localstorage before closing a page

Cloud native observability tracking technology in the eyes of Baidu engineers

Password input box and coupon and custom soft keyboard
随机推荐
Screenshot of Baidu map
C language word translation (to help understand the basic meaning of words) is updated from time to time
What is iftmcs indicating contract status message?
Opengauss kernel analysis: query rewriting
Latex notes
Chapter III kernel development
Summary of MATLAB basic grammar
How SAP Spartacus redefines login component
Moonpdflib Preview PDF usage record
Resolution of multi thread conflict lock
Ad active directory and domain network
Fabric. JS centered element
10 commonly used data visualization tool software
What is the root password of MySQL initial installation
"Usaco2006nov" corn fields solution
Solution to the shortest Hamilton path problem
Nacos hand to hand teaching [i] dynamic configuration of Nacos
WhatsApp web for usability testing of software testing technology
[C + + primer notes] Chapter 6 functions
The position of the nth occurrence of MySQL in the string