NYOJ 19擅长排列的小明
2017-08-04 16:41
302 查看
擅长排列的小明
时间限制:1000 ms | 内存限制:65535 KB难度:4
描述小明十分聪明,而且十分擅长排列计算。比如给小明一个数字5,他能立刻给出1-5按字典序的全排列,如果你想为难他,在这5个数字中选出几个数字让他继续全排列,那么你就错了,他同样的很擅长。现在需要你写一个程序来验证擅长排列的小明到底对不对。
输入第一行输入整数N(1<N<10)表示多少组测试数据,
每组测试数据第一行两个整数 n m (1<n<9,0<m<=n)
输出在1-n中选取m个字符进行全排列,按字典序全部输出,每种排列占一行,每组数据间不需分界。如样例
样例输入
2 3 1 4 2
样例输出
1 2 3 12 13 14 21 23 24 31 32 34 41 4000 42 43
来源[hzyqazasdf]原创
上传者
hzyqazasdf
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int N,i;
cin>>N;
while(N--)
{
int n,m;
string str1,str2;
cin>>n>>m;
for(i=1;i<=n;i++)
{
str1+=i+'0';
}
str2=str1.substr(0,m);
cout<<str2<<endl;
do
{
if(str2!=str1.substr(0,m))
{
str2=str1.substr(0,m);
cout<<str2<<endl;
}
}while(next_permutation(str1.begin(),str1.end()));
}
return 0;
}
相关文章推荐
- nyoj 19 擅长排列的小明
- NYOJ 19(擅长排列的小明)
- NYOJ 题目19 擅长排列的小明(dfs)
- nyoj 19 擅长排列的小明
- nyoj_19_擅长排列的小明_201403011600
- nyoj19 擅长排列的小明
- NYOJ - 19 - 擅长排列的小明(STL - set +全排列)
- NYOJ 19 擅长排列的小明
- nyoj-19 擅长排列的小明 (dfs)
- nyoj 19 擅长排列的小明
- nyoj 19 擅长排列的小明
- nyoj--19--擅长排列的小明(dfs)
- NYOJ 19 擅长排列的小明
- NYOJ-19 擅长排列的小明 -----回溯
- NYOJ 19 擅长排列的小明 DFS
- nyoj--19--擅长排列的小明(dfs)
- nyoj 19 擅长排列的小明
- nyoj19擅长排列的小明(DFS或STL)
- nyoj 19 擅长排列的小明
- NYOJ 19--擅长排列的小明【DFS】