#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
vector<string> paths;
int n;
bool cmp(string a, string b) {
if(a.length() != b.length()) return a.length() < b.length();
return a < b;
}
int sum_(string a) {
int ans = 0;
for(int i=0; i<a.size(); ++i) ans += (a[i]-'0');
return ans;
}
void bfs(vector<string>& now_path) {
if(now_path.size() == 0) {
return;
}
int x = now_path.size();
for(int i=0; i<x; ++i) {
for(int j=1; j<=min(n-sum_(now_path[0]), 2); ++j) {
string temp = now_path[0] + char(j+'0');
if(sum_(temp) == n)
paths.push_back(temp);
else
now_path.push_back(temp);
}
now_path.erase(now_path.begin());
}
bfs(now_path);
}
int main()
{
vector<string> now_path;
cin >> n;
if(n>0) now_path.push_back("1");
if(n>1) now_path.push_back("2");
bfs(now_path);
sort(paths.begin(), paths.end(), cmp);
for(int i=0; i<paths.size(); ++i) {
cout << paths[i] << endl;
}
return 0;
}
|