当前位置:网站首页>[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));
}边栏推荐
- How to create an index
- ES6 modularization
- Introduction to thread pool
- Password input box and coupon and custom soft keyboard
- Turn: emotional internal friction is the biggest source of inefficiency in your life
- Summary of MATLAB basic grammar
- Divide 300000 bonus! Deeperec CTR model performance optimization Tianchi challenge is coming
- 10 commonly used data visualization tool software
- The two supply chain centers of HEMA launched the "background" of innovative research and development of multi format commodities
- Breederdao's first proposal was released: the constitution of the Dao organization
猜你喜欢
![[C + + primer notes] Chapter 8 IO Library](/img/84/53cca8bb00b392c74b5dfe039da711.png)
[C + + primer notes] Chapter 8 IO Library

If in ython__ name__ == ‘__ main__‘: Function and principle of

7.19 - daily question - 408

Synchronization primitive: lock

Worthington cytochrome c digestion study carboxypeptidase B scheme
![[25. Hash table]](/img/c4/1500d070d44d3bd84eb141ed38013d.png)
[25. Hash table]

Chip sold at sand price: Lei Jun's dream was "ruined" by this company

Multi species tissue slide prosci pancreatic tissue solution

What is the root password of MySQL initial installation

Kusionstack open source | exploration and practice of kusion model library and tool chain
随机推荐
Top priority of dry goods: common indicators and terms in data analysis!
Summary of MATLAB basic grammar
[performance optimization] MySQL common slow query analysis tools
Codeworks round 649 (Div. 2) ABC problem solution
If in ython__ name__ == ‘__ main__‘: Function and principle of
JS convert pseudo array to array
Summary of the most complete MySQL data types in history (Part 2)
Brush questions of binary tree (5)
About the difference between for... In and for... Of and object. Keys()
Unity panel control
Several states of the process
[C + + primer notes] Chapter 8 IO Library
Wireshark introduction and packet capturing principle and process
Latex notes
Redis 事务学习有感
Chip sold at sand price: Lei Jun's dream was "ruined" by this company
Take C language from 0 to 1 - program structure and use examples
Record the bugs encountered and some work experience
Heavy forecast! Analysys, together with Microsoft and the Central University of Finance and economics, talks about the digital economy
Solution to the shortest Hamilton path problem