Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n,st[20],a[1001],L,S;
- void BACK(int top,int suma)
- {
- if(top==(L+1) && suma<=S)
- {
- for(int i=1;i<=L;i++)
- cout<<a[st[i]]<<" ";
- cout<<"\n";
- }
- else for(int i=1;i<=n && suma+a[i]<=S;i++)
- {
- st[top]=i;
- suma+=a[i];
- BACK(top+1,suma);
- suma-=a[i];
- }
- }
- int main()
- {
- cin>>n>>L>>S;
- for(int i=1;i<=n;i++)
- cin>>a[i];
- BACK(1,0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement