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],S;
- void BACK(int top,int suma)
- {
- if(top==(n+1) && suma==S)
- {
- for(int i=1;i<=n;i++)
- cout<<st[i];
- cout<<"\n";
- }
- else
- {
- for(int i=1;i<=9 && top<=n && suma+i<=S;i++)
- {
- suma+=i;
- st[top]=i;
- BACK(top+1,suma);
- suma-=i;
- }
- }
- }
- int main()
- {
- cin>>n>>S;
- BACK(1,0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement