组合排列

Input

Input contains a single line with all labels of the requested goods (in random order). Each kind of goods is represented by the starting letter of its label. Only small letters of the English alphabet are used. The number of orders doesn‘t exceed 200.

Output

Output will contain all possible orderings in which the stores manager may visit his warehouses. Every warehouse is represented by a single small letter of the English alphabet -- the starting letter of the label of the goods. Each ordering of warehouses is written in the output file only once on a separate line and all the lines containing orderings have to be sorted in an alphabetical order (see the example). No output will exceed 2 megabytes.

Sample Input

bbjd

Sample Output

bbdj
bbjd
bdbj
bdjb
bjbd
bjdb
dbbj
dbjb
djbb
jbbd
jbdb
jdbb

函数生成排列组合序列
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
	char s[300];
	int len;
	while(scanf("%s", s)!=EOF)
	{
		len = strlen(s);
		sort(s, s+len);
		do
		{
			printf("%s\n", s);
		}while(next_permutation(s, s+len));
	}
	return 0;
}
				
时间: 2024-08-09 11:35:11

组合排列的相关文章

PHP数组内容不重复组合排列算法

最近在做ecshop的商品库存模块,分别给一款商品的多个属性组合设置库存,如下图: 一款手机有不同颜色,屏幕尺寸,系统和电量,都要设置不同的库存,如果都要手动选择属性组合,则会耗费很多不必要的时间.假如打开页面时就已经设置好属性排列组合那就最好不过,因此想了整天,写了如下函数: 1 <?php 2 3 /* 4 Author:GaZeon 5 Date:2016-6-20 6 Function:getArrSet 7 Param:$arrs 二维数组 8 getArrSet(array(arra

LightOJ 1005 Rooks(组合排列)或(dp,还得再看看)

n*n的棋盘中,放k个棋子,每个棋子不能同行同列 1 #include<cstdio> 2 #include<iostream> 3 #include<queue> 4 #include<string> 5 #include<math.h> 6 #include<stack> 7 #include<cstdlib> 8 #include<set> 9 #include<map> 10 #includ

递归算法之类循环组合排列

输入: 给定数据,输入n,m.分别代表位数,可能取到的值. 输出: 输出所有可能的数字. 样例输入: 4 2 样例输出: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 题目分析: 这是一种典型的递归算法-------类递归组合排列. 代码如下: <span style="font-size:14px;">#include<stdio.h> int n

组合排列的实现方法

最近在做数据分析系统,里面涉及到组合排列的问题,查找了很多的资料,但是感觉很多资料都是比较零散的,达不到项目需求. 后来经过一段的时间的探索,终于实现了组合排列的功能.下面我就来简单说说吧. 需求描述:   要实现的功能就是字符或数字的组合排列.例如:ab 的所有组合为:ab,ba :  ab的所有不重复排列为:ab. 其实这也是彩票中常说的直选和组选.效果图如下: 功能实现 这里就不多说了,直接贴上实现代码吧. 1.窗体界面设计 设计代码: 1 partial class FrmDemo 2

递归求解几类排列组合问题(一、类循环组合排列)

对于搜索的深度很深或深度不固定的情况,则无法用枚举的方法来设置循环嵌套的层数,这时可以考虑用递归法来完成搜索任务.递归是一种常用算法,它是搜索的另一种实现方式.如果在算法设计中采用一个函数或过程直接或间接地调用它自身来解决问题的方法,则称该方法为递归算法.递归算法必须要设计好一个或若干个确定的递归终止条件. 一.类循环组合排列 Sample Input : 4 2 Sample Output 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 10

递归求解几类排列组合问题(二、全组合排列)

对于搜索的深度很深或深度不固定的情况,则无法用枚举的方法来设置循环嵌套的层数,这时可以考虑用递归法来完成搜索任务.递归是一种常用算法,它是搜索的另一种实现方式.如果在算法设计中采用一个函数或过程直接或间接地调用它自身来解决问题的方法,则称该方法为递归算法.递归算法必须要设计好一个或若干个确定的递归终止条件. Sample Input 3 1 2 3 Sample Output 123 132 213 231 312 321 #include<stdio.h> #include<strin

递归求解几类排列组合问题(三、非重复组合排列)

三.非重复组合排列(含重复数字时,生成不重复组合排列) 对于搜索的深度很深或深度不固定的情况,则无法用枚举的方法来设置循环嵌套的层数,这时可以考虑用递归法来完成搜索任务.递归是一种常用算法,它是搜索的另一种实现方式.如果在算法设计中采用一个函数或过程直接或间接地调用它自身来解决问题的方法,则称该方法为递归算法.递归算法必须要设计好一个或若干个确定的递归终止条件. Sample Input 4 1 2 2 3 Sample Output 1223 1232 1322 2123 2132 2213

递归求解几类排列组合问题(四、普通选择性组合排列)

四.普通选择性组合排列 对于搜索的深度很深或深度不固定的情况,则无法用枚举的方法来设置循环嵌套的层数,这时可以考虑用递归法来完成搜索任务.递归是一种常用算法,它是搜索的另一种实现方式.如果在算法设计中采用一个函数或过程直接或间接地调用它自身来解决问题的方法,则称该方法为递归算法.递归算法必须要设计好一个或若干个确定的递归终止条件. Sample Input 5 3 1 2 3 4 5 Sample Output 123 124 125 134 135 145 234 235 245 345 #i

数组组合排列及排序

//组合排列let array = ['1','2','3'] function getGroup(data, index = 0, group = []) { let need_apply = []; need_apply.push(data[index]); for (var i = 0; i < group.length; i++) { need_apply.push(group[i] + ' ' + data[index]); } group.push.apply(group, need