#include<stdio.h>
#include <string.h>
int d[25];
void Permutation(int s[], int i, int l);
int
count = 0;
void main()
{
int N;
int i,j,k,s;
int a[25];
scanf("%d",&N);
for(i=0;i<=N/3;i++)
for(j=0;j<=N/2;j++)
for(k=0;k<=N;k++)
{
memset(a,'\0',sizeof(a));
if(3*i+2*j+k==N)
{
if(k!=0)
{
for(s=0;s<k;s++)
a[s]=1;
}
if(j!=0)
{
for(s=k;s<j+k;s++)
a[s]=2;
}
if(i!=0)
{
for(s=j+k;s<j+k+i;s++)
a[s]=3;
}
Permutation(a, 0, i+j+k);
}
}
}
void Permutation(int s[], int i, int n)
{
int j,k=0;
int temp;
for(j = 0; j < n; j ++)
if(s[j] == s[j - 1])
;
else if(s[j] != '#')
{
d[i] = s[j];
temp = s[j];
s[j] = '#';
if(i == n - 1)
{
d[n] = '\0';
printf("%d:\t", ++ count);
while(d[k]!='\0')
printf("%d\t",d[k++]);
printf("\n");
}
else Permutation(s, i + 1, n);
s[j] = temp;
}
}
贴一下!