Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int st[100], i, n, s;
- void backtrack(int k)
- {
- if(s == n)
- {
- for(i = 1; i < k; i++)
- cout << st[i] << " ";
- cout << "\n";
- }
- else
- {
- st[k] = 0;
- while(st[k]+s < n)
- {
- st[k]++;
- s += st[k];
- backtrack(k+1);
- s -= st[k];
- }
- }
- }
- int main()
- {
- cin >> n;
- backtrack(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement