lightoj 1023

题意:让你输出前N个大写字母的前K个排列,按字典序,很水,直接dfs。

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int vis[26], N, K, cnt;
void dfs(int dep, string str){
if(cnt == K) return;
if(dep == N){
cout << str << endl;
cnt ++;
return;
}
for(int i = 0;i < N;i ++){
if(!vis[i]){
vis[i] = 1;
char ch = i + 'A';
dfs(dep + 1, str + ch);
if(cnt == K) return;
vis[i] = 0;
}
}
}
int main(){
int t,CASE(0);
scanf("%d", &t);
while(t--){
cnt = 0;
memset(vis, 0, sizeof vis);
scanf("%d%d", &N, &K);
printf("Case %d:\n", ++CASE);
dfs(0, "");
}
return 0;
}
上一篇:UEditor 1.4.3.1.NET版本上传配置备忘录


下一篇:[跟我学spring学习笔记][DI循环依赖]