#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
int n;
int num;
vector<int> v, ans;
bool compare(){
for (int i = 0; i < n+1; ++i){
if(v[i] != ans[i])
return v[i] > ans[i];
}
return false;
}
void dfs(int x){
if (x > n){
if(compare())
ans = v;
num++;
return;
}
for(int i = 1; i < x ;++i){
if( x % (v[i-1] + v[i]) == 0 ){
v.insert(v.begin()+i, x);
dfs(x+1);
v.erase(v.begin()+i);
}
}
}
int main(){
scanf("%d",&n);
v.push_back(0);
v.push_back(1);
num = 0;
for (int i = 0; i <= n; ++i)
ans.push_back(0);
dfs(2);
printf("%d\n",num);
for (int i = 0; i < n; ++i){
printf("%d ",ans[i]);
}
printf("%d\n",ans[n]);
}
2015年1月28日 星期三
TIOJ 1020 F.Number Insertion
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言