目录
一、问题描述
二、代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<string>
#include<stdio.h>
using namespace std;
string r(string s, string c, string y){
int n = c.length();
int m = s.length();
string ss = "";
for(int pos = 0,p = 0; pos < m;p++, pos++){
if(s.substr(pos, n) == c){
ss = ss + y;
pos = pos + n - 1;
}
else ss.push_back(s[pos]);
}
return ss;
}
string spt(string s, char x){
int m = s.length();
string ss = "";
for(int i = 0; i < m; i++){
if(s[i]==x){
break;
}
else ss.push_back(s[i]);
}
return ss;
}
void split(string sp,string st,int max){
if(st==""){
cout<<sp<<endl;
return;
}
string temp[] = {spt(sp, '|')};
for(int i=0;i<st.length();i++){
int code=st[i];
string c = "";
c.push_back(st[i]);
st=r(st, c, "");
if(code>max){
if(!(sp=="")){
for(int j=0;j < sizeof(temp) / sizeof(temp[0]);j++){
string d = "";
d = d +c+temp[j];
string f = "";
f = f + r(sp, temp[j],d);
split(f,st,code);
}
}
string e = "";
string str = "";
e = e + sp+'|'+c;
str=(sp=="")?c:e;
split(str,st,code);
}
}
}
//给定正整数n 和m,计算出n 个元素的集合{1,2,., n }可以划分为多少个不同的由m 个非空子集组成的集合。
long long q(long long m,long long n)
{
if(m==1)
return 1;
if(m==n)
return 1;
else
return q(m-1,n-1)+q(m,n-1)*m;
}
int main()
{
long i;
long n,sum=0;
cin>>n;
cout<<endl;
for(i=1; i<=n; i++){
sum+=q(i,n);
}
cout<<sum<<endl<<endl;
split("", "123456",-1);
return 0;
}