擅长排列的小明

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
 
描述
小明十分聪明,而且十分擅长排列计算。比如给小明一个数字5,他能立刻给出1-5按字典序的全排列,如果你想为难他,在这5个数字中选出几个数字让他继续全排列,那么你就错了,他同样的很擅长。现在需要你写一个程序来验证擅长排列的小明到底对不对。
 
输入
第一行输入整数N(1<N<10)表示多少组测试数据,
每组测试数据第一行两个整数 n m (1<n<9,0<m<=n)
输出
在1-n中选取m个字符进行全排列,按字典序全部输出,每种排列占一行,每组数据间不需分界。如样例
样例输入
  1. 2
  2. 3 1
  3. 4 2
样例输出
  1. 1
  2. 2
  3. 3
  4. 12
  5. 13
  6. 14
  7. 21
  8. 23
  9. 24
  10. 31
  11. 32
  12. 34
  13. 41
  14. 42
  15. 43
    给定1n的数,求x位数的全排列
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8. int n,k,num,i;
  9. char a[],b[];
  10. cin>>n;
  11. while(n--)
  12. {
  13. cin>>k>>num;
  14. for(i=;i<k;i++)
  15. a[i]=''+i+;
  16. a[k]='\0';
  17. for(i=;i<num;i++)
  18. cout<<a[i];
  19. cout<<endl;
  20. strcpy(b,a);
  21. while(next_permutation(a,a+k))
  22. {
  23. int flag=;
  24. for(i=;i<num;i++)
  25. {
  26. if(a[i]!=b[i])
  27. {
  28. flag=;
  29. }
  30. }
  31. if(flag)
  32. {
  33. for(i=;i<num;i++)
  34. cout<<a[i];
  35. cout<<endl;
  36. strcpy(b,a);
  37. }
  38. else
  39. continue;
  40. }
  41. }
  42. }
  1.  
  1.  

x位全排列(next_permutation)的更多相关文章

  1. 全排列next_permutation()用法和构造函数赋值

    全排列next_permutation()用法 在头文件aglorithm里 就是1~n数组的现在的字典序到最大的字典序的依次增加.(最多可以是n!种情况) int a[n]; do{ }while( ...

  2. 全排列 next_permutation 用法

    给一个正整数n,让你求它的全排列 先介绍一个函数,iota(a,a+n,1) 用法就是把a数组的第0位到第n-1位依次赋为1,2,.....n: 然后是next_permutation(a,a+4)函 ...

  3. 排列2(全排列next_permutation 注意格式)

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. STL中关于全排列next_permutation以及prev_permutation的用法

    这两个函数都包含在algorithm库中.STL提供了两个用来计算排列组合关系的算法,分别是next_permutation和prev_permutation. 一.函数原型 首先我们来看看这两个函数 ...

  5. 关于全排列 next_permutation() 函数的用法

    这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...

  6. 全排列 ( next_permutation)

    SLT: C++的STL有一个函数可以方便地生成全排列,这就是next_permutation 在C++ Reference中查看了一下next_permutation的函数声明: #include ...

  7. 蓝桥杯 方格填数 DFS 全排列 next_permutation用法

    如下的10个格子(参看[图1.jpg]) 填入0~9的数字.要求:连续的两个数字不能相邻.(左右.上下.对角都算相邻) 一共有多少种可能的填数方案? 请填写表示方案数目的整数.注意:你提交的应该是一个 ...

  8. 全排列 next_permutation() 函数的用法

    在头文件<algorithm>里面有如下代码: int a[]; do { } while(next_permutation(a,a+n)); 可产生1~n的全排列有如下代码: #incl ...

  9. 全排列 next_permutation() 函数的使用

    看来看去还是这篇博客比较简洁明了 https://www.cnblogs.com/My-Sunshine/p/4985366.html 顺便给出牛客网的一道题,虽然这道题用dfs写出全排列也能做,题意 ...

随机推荐

  1. mvc4 基于Area实现插件模块化开发

    对于一个较大规模的Web应用,可以从功能上通过Area将其划分为为较小的单元.每个Area相当于一个独立的子系统,具有一套包含Model.Views和Controller在内 的目录结构和配置文件.一 ...

  2. jquery checkbox 全选、取消全选

    $("#checkall").click(function(){ $("input[name='uid']").prop("checked" ...

  3. UltraChart导出图片

    ? //一定要先绑定UltraChart,如果先绑定,然后有点击图片导出,没有用的 string fulPath="xxxx"; this.UltraChartTScore.Sav ...

  4. Dynamics CRM 2013 初体验(2):UI

    Dynamics CRM 2013 系统的UI与2011相比改动是巨大的:传统的导航栏被去掉了,取代它的是win8风格的小磁铁:Ribbon风格的工具栏也被去掉啦,它的风格将回滚至4.0时代:新系统添 ...

  5. if switch练习(体重)

    public class shencai { public static void main(String[] args) { int h= 186,g= 80; String Sex = " ...

  6. Ubuntu 配置Tomcat环境

    1.下载Tomcat http://tomcat.apache.org/,下载Tomcat 8(由于目前最新eclipse不支持tomcat 9) 将下载的apache-tomcat-8.0.35.t ...

  7. for添加用户

    #!/bin/bash #接受一个参数: #add: 添加用户user1..user10 #del: 删除用户user1..user10 #其它:退出 #定义变量 ADD=add DEL=del #判 ...

  8. jquery 鼠标图片经过效果

    <script> //鼠标图片经过效果 $(function(){ $(".jione_box ").css("background-color", ...

  9. qt反走样(简选)

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #qt反走样(简选) #概念 """ ...

  10. UIImage图片处理

    #pragma mark - #pragma mark - 缩放处理 + (UIImage *)scaleImage:(UIImage *)image withScale:(float)scale { ...