Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n, st[20], l[20], c[20], k;
- void init(){
- st[k]=0;
- }
- int succesor(){
- if(st[k]<n){
- st[k]++;
- return 1;
- }
- return 0;
- }
- int valid(){
- int i;
- for(i=1; i<k; i++){
- if(st[i] == st[k])
- return 0;
- }
- return 1;
- }
- int solutie(){
- int i, s=0;
- /*if(k<2) return 0; //min 2 numere*/
- for(i=1;i<=k;i++)
- s=s+st[i];
- return s==n;
- }
- int solfin(){
- return k==n;
- }
- void tipar(){
- int i;
- for(i=1; i<=k; i++)
- cout<<st[i]<<" ";
- cout<<endl;
- }
- void back(){
- int as;
- k=1;
- init();
- while(k>0){
- do{}while((as=succesor())&&!valid());
- if(as==1){
- if(solutie()==1){
- tipar();
- }
- if(solfin()==0){
- k++;
- init();
- }
- }else{
- k--;
- }
- }
- }
- int main(){
- cin>>n;
- back();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement