n个数的全排列,但是可以次次输入一个数,两个数
n个数的全排列,但是可以每次输入一个数,两个数?
例如1,2,3有15种可能。
⑴ 1
⑵ 1 2
⑶ 1 2 3
⑷ 1 3
⑸ 1 3 2
⑹ 2
⑺ 2 1
⑻ 2 1 3
⑼ 2 3
⑽ 2 3 1
⑾ 3
⑿ 3 1
⒀ 3 1 2
⒁ 3 2
⒂ 3 2 1
------解决方案--------------------
p(3,3)+p(3,2)+p(3,1)=15
------解决方案--------------------
大小通杀!

例如1,2,3有15种可能。
⑴ 1
⑵ 1 2
⑶ 1 2 3
⑷ 1 3
⑸ 1 3 2
⑹ 2
⑺ 2 1
⑻ 2 1 3
⑼ 2 3
⑽ 2 3 1
⑾ 3
⑿ 3 1
⒀ 3 1 2
⒁ 3 2
⒂ 3 2 1
------解决方案--------------------
p(3,3)+p(3,2)+p(3,1)=15
------解决方案--------------------
大小通杀!
//qplw.cpp
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int v=0;
int w=0;
int m;//记录字符串长度
int n;//记录字符串中的字符种类数
char map[256];//记录是哪几种字符
int count[256];//记录每种字符有多少个
int stack[1000];//递归用的栈,并记录当前生成的排列
void Make_Map(char *str) {//统计字符串的相关信息
int s[256];
int i;
memset(s,0,sizeof(s));
memset(count,0,sizeof(count));
m=strlen(str);
if (w<1
------解决方案--------------------
m<w) w=m;
while(*str) {
s[*str]++;
str++;
}
n=0;
for (i=0;i<256;i++)
if (s[i]) {
map[n]=i;
count[n]=s[i];
n++;
}
}
void Find(int depth) {//递归式回溯法生成全排列
if (depth==w) {
int i;
for (i=0;i<depth;i++) putchar(map[stack[i]]);
putchar('\n');