Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Daniel Grzegorzewski
- #include <bits/stdc++.h>
- #define MP make_pair
- #define PB push_back
- #define ST first
- #define ND second
- using namespace std;
- typedef pair<int, int> PII;
- typedef vector<int> VI;
- typedef vector<PII> VII;
- void init_ios()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- }
- int n, res = 3000;
- bool mamy[3000];
- VI ruchy;
- void bt(VI &s, int wyn, int id)
- {
- if (res > wyn+1 && mamy[n-s.back()]) {
- res = wyn+1;
- ruchy = s;
- return;
- }
- if (wyn+1 >= res)
- return ;
- while (s.back()+s[id] > n)
- --id;
- for (int i = id; i >= 0; --i) {
- s.PB(s.back()+s[i]);
- mamy[s.back()] = true;
- bt(s, wyn+1, id+1);
- mamy[s.back()] = false;
- s.pop_back();
- if (wyn+1 >= res)
- return;
- }
- }
- int main()
- {
- init_ios();
- cin >> n;
- if (n == 1) {
- cout<<"0\n1\n";
- return 0;
- }
- VI s;
- s.PB(1);
- mamy[1] = true;
- if (n >= 700)
- for (int j = 2; j <= 64; j *= 2) {
- s.PB(j);
- mamy[j] = true;
- }
- if (n >= 700)
- bt(s, 6, 6);
- else
- bt(s, 0, 0);
- ruchy.PB(n);
- cout<<res<<"\n";
- for (int i = 0; i < ruchy.size(); ++i)
- cout<<ruchy[i]<<" ";
- cout<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement