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