10098 - Generating Fast
/*
生成可重集的排列,详解见刘汝佳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相关推荐
- uva 10098 Generating Fast(全排列)
还是用的两种方法,递归和STL,递归那个是含有反复元素的全排列,这道题我 没有尝试没有反复元素的排列,由于从题目上并没有发现一定是有反复元素的() 贴代码: <span style=" ...
- π-Algorithmist分类题目(1)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...
- 提取了下刘汝佳推荐的题号...
今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started 10055 - Hashmat the Brave Warrior ...
- ICPC训练联盟2021寒假冬令营(9)_2021.01.29_笔记
试题链接 点我进入代码提交OJ 学习笔记 - 数论与组合分析入门 数论的编程实验 • 3.1素数运算的实验范例 • 3.2求解不定方程和同余方程的实验范例 • 3.3 特殊的同余式 • 3.4 积性函 ...
- Competitive Programming 3题解
题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...
- AOAPC I: Beginning Algorithm Contests 题解
AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...
- ICPC程序设计题解书籍系列之六:吴永辉:《算法设计编程实验》
第1章 Ad Hoc问题 POJ2661 HDU1141 ZOJ2545 UVA10916 Factstone Benchmark[Ad Hoc] UVA10037 Bridge[贪心] POJ257 ...
- DMC-Net: Generating Discriminative Motion Cues for Fast Compressed Video Action Recognition 论文赏析
DMC-Net: Generating Discriminative Motion Cues for Fast Compressed Video Action Recognition 论文赏析 前言 ...
- Paper:《Generating Sequences With Recurrent Neural Networks》的翻译和解读
Paper:<Generating Sequences With Recurrent Neural Networks>的翻译和解读 目录 Generating Sequences With ...
- faster rcnn学习之rpn、fast rcnn数据准备说明
在上文< faster-rcnn系列学习之准备数据>,我们已经介绍了imdb与roidb的一些情况,下面我们准备再继续说一下rpn阶段和fast rcnn阶段的数据准备整个处理流程. 由于 ...
最新文章
- python安装依赖失败_python - pip安装jq依赖关系失败 - SO中文参考 - www.soinside.com
- PonyAI的首份美国无人出租成绩单:总数1271趟,15%拼车
- 完成users中的models
- iOS逆向之iOSOpenDev
- 实战并发编程 - 03基于不可变模式解决并发问题_1
- 注册表中shell文件不见了_win7系统注册表中的shell文件不小心被删除的解决方法...
- css中变量_CSS中的变量
- MYSQL 时间处理
- c#winform选择文件,文件夹,打开指定目录方法
- 跟着团子学SAP:售前项目、项目前期管理思路
- vue调用服务器图片
- 半年以来的图像去雾总结-图像去雾(一)暗通道去雾
- 微信小游戏SDK,全方位解读
- 【java删除指定文件夹或者文件】
- 高斯消元法(高斯·约当消元法)(浮点)
- 基于Matlab的火灾预警系统
- 如何把自己的百度网盘的内容分享给别人
- Google Play关键词排名优化
- Oracle错误一览表
- 投票点赞链接制作投票链接在线制作投票图文链接制作点赞