/*
生成可重集的排列,详解见刘汝佳p118
题意:输出字符串的全排列,输出时由小到大排序
*/#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char str[15];
void print_permutation(int n,int *A,int cur)//递归技巧:传递一数组过来存储已确定的前缀(***)
{int i,j;if(cur==n){for(i=0;i<n;i++)printf("%c",A[i]);printf("\n");}else for(i=0;i<n;i++)if(!i || str[i]!=str[i-1])//保证重复的字符只选一次{int c1=0,c2=0;for(j=0;j<cur;j++) if(str[i]==A[j]) c1++;for(j=0;j<n;j++) if(str[i]==str[j]) c2++;if(c1<c2){A[cur]=str[i];print_permutation(n,A,cur+1);}}
}
int main()
{//freopen("data.in","r",stdin);int n;scanf("%d",&n);while(n--){int A[15];scanf("%s",str);int len=strlen(str);sort(str,str+len);print_permutation(len,A,0);printf("\n");}return 0;
}

STL解法

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{int T;scanf("%d",&T);while(T--){char str[15];scanf("%s",str);int len=strlen(str);sort(str,str+len);do{printf("%s\n",str);}while(next_permutation(str,str+len));printf("\n");}return 0;
}

10098 - Generating Fast相关推荐

  1. uva 10098 Generating Fast(全排列)

    还是用的两种方法,递归和STL,递归那个是含有反复元素的全排列,这道题我 没有尝试没有反复元素的排列,由于从题目上并没有发现一定是有反复元素的() 贴代码: <span style=" ...

  2. π-Algorithmist分类题目(1)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...

  3. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

  4. ICPC训练联盟2021寒假冬令营(9)_2021.01.29_笔记

    试题链接 点我进入代码提交OJ 学习笔记 - 数论与组合分析入门 数论的编程实验 • 3.1素数运算的实验范例 • 3.2求解不定方程和同余方程的实验范例 • 3.3 特殊的同余式 • 3.4 积性函 ...

  5. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  6. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  7. ICPC程序设计题解书籍系列之六:吴永辉:《算法设计编程实验》

    第1章 Ad Hoc问题 POJ2661 HDU1141 ZOJ2545 UVA10916 Factstone Benchmark[Ad Hoc] UVA10037 Bridge[贪心] POJ257 ...

  8. DMC-Net: Generating Discriminative Motion Cues for Fast Compressed Video Action Recognition 论文赏析

    DMC-Net: Generating Discriminative Motion Cues for Fast Compressed Video Action Recognition 论文赏析 前言 ...

  9. Paper:《Generating Sequences With Recurrent Neural Networks》的翻译和解读

    Paper:<Generating Sequences With Recurrent Neural Networks>的翻译和解读 目录 Generating Sequences With ...

  10. faster rcnn学习之rpn、fast rcnn数据准备说明

    在上文< faster-rcnn系列学习之准备数据>,我们已经介绍了imdb与roidb的一些情况,下面我们准备再继续说一下rpn阶段和fast rcnn阶段的数据准备整个处理流程. 由于 ...

最新文章

  1. python安装依赖失败_python - pip安装jq依赖关系失败 - SO中文参考 - www.soinside.com
  2. PonyAI的首份美国无人出租成绩单:总数1271趟,15%拼车
  3. 完成users中的models
  4. iOS逆向之iOSOpenDev
  5. 实战并发编程 - 03基于不可变模式解决并发问题_1
  6. 注册表中shell文件不见了_win7系统注册表中的shell文件不小心被删除的解决方法...
  7. css中变量_CSS中的变量
  8. MYSQL 时间处理
  9. c#winform选择文件,文件夹,打开指定目录方法
  10. 跟着团子学SAP:售前项目、项目前期管理思路
  11. vue调用服务器图片
  12. 半年以来的图像去雾总结-图像去雾(一)暗通道去雾
  13. 微信小游戏SDK,全方位解读
  14. 【java删除指定文件夹或者文件】
  15. 高斯消元法(高斯·约当消元法)(浮点)
  16. 基于Matlab的火灾预警系统
  17. 如何把自己的百度网盘的内容分享给别人
  18. Google Play关键词排名优化
  19. Oracle错误一览表
  20. 投票点赞链接制作投票链接在线制作投票图文链接制作点赞

热门文章

  1. 软件测试度量的关键指标,软件测试度量指标简介
  2. 挺有意思的文章。。。
  3. 如何把照片kb缩小?详细步骤
  4. 解放双手, python自动化操作电脑端微信
  5. 【零基础】speech driven animation中文安装使用指南
  6. 四阶行列式如何降阶_四阶行列式的计算方法
  7. M1芯片,PS2022版真的来了。Photoshop 2022 for Mac中文版介绍安装教程,支持Monterey系统
  8. 数据库中制作一个拼音缩写查询函数
  9. 《禅者的初心》读书笔记(3)
  10. 李国庆与当当,一个中国网络书店的传奇