1 solutions
-
1
暴搜选择,用
vis
标记,把结果放到box
里面,然后输出就可以了。#include<bits/stdc++.h> using namespace std; int box[25]; bool vis[25]; int n,m; void dfs(int x,int lst){ if(x==n+1) { for(int i=1;i<=n;i++){ cout<<" "<<box[i]; } cout<<'\n'; return ; } for(int i=lst;i<=m;i++){ if(!vis[i]) { box[x]=i; vis[i]=1; dfs(x+1,i); vis[i]=0; } } } int main(){ cin>>m>>n; dfs(1,1); return 0; }
- 1
Information
- ID
- 597
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 22
- Accepted
- 9
- Uploaded By