Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- using namespace std;
- map <int, int> pr;
- void ans() {
- while(val) {
- col++;
- b[col] = val - pr[val];
- val = pr[val];
- }
- if (col == 0)
- cout << -1;
- else {
- cout << col << endl;
- for (int i = 1; i <= col; i++)
- cout << b[col] << ' ';
- }
- }
- void go(int s, int i) {
- if (s == 0) {
- ans();
- return;
- }
- pr[s] = pr[s - a[i]];
- pr[s - a[i]] = pr[s - a[i] - a[i]];
- go(s, i + 1);
- go(s - a[i], i + 1);
- go(s - a[i] - a[i], i + 1);
- }
- int main() {
- cin >> val >> n;
- for (int i = 1; i <= n; i++)
- cin >> a[i];
- go(val, 1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement