litere

Se citesc n litere.Sa se formeze toate cuvintele de cate p litere formate din cele n litere astfel incat aceeasi litera sa nu se afle pe 2 pozitii alaturate. #include<iostream.h>#include<conio.h> int n,st[10],k,p;char v[10]; int valid(int k){if((k>1) && (st[k]==st[k-1])) return 0;return 1;} int sol(int k){return (k==p);} void tipar(int p){for(int i=1;i<=p;i++)cout<<v[st[i]];cout<<endl;} void bkt(int k){ for(int val=1;val<=n;val++){st[k]=val;if (valid(k)) if (sol(k)) … Read more

nr negative alaturate

se citesc n nr.sa se afle toate modalitatile de afisare a nr a.i. 2 nr alaturate sa nu fie negative #include<iostream.h>int st[20],n,k,v[20]; void init(){cout<<“n=”;cin>>n;} int valid(int k){for(int i=1;i<k;i++) if(st[i]==st[k]) return 0;if((v[st[k]]<0) && (v[st[k-1]]<0)) return 0;return 1;} int sol(int k){return (k==n);} void tipar(int k){for(int i=1;i<=k;i++) cout<<v[st[i]];cout<<endl;} void bkt(int k){int val; for(val=1;val<=n;val++) {st[k]=val; if(valid(k)) if (sol(k)) tipar(k); … Read more

combinari

//combinari#include<iostream.h>int st[20],n,k; void init(){int i;cout<<“n=”;cin>>n;cout<<“k=”;cin>>k;st[0]=0;} void tipar(int p){int j;for(j=1;j<=p;j++)cout<<st[j]<<” “;cout<<endl;} int solutie(int p){return (p==k);} void bkt(int p){int val;for (val=st[p-1]+1;val<=n;val++){st[p]=val;if(solutie(p))tipar(p);elsebkt(p+1);}} void main(){init();bkt(1);} {joscommentenable}

aranjamente

//aranjamente#include<iostream.h>int st[20],n,k; void init(){int i;cout<<“n=”;cin>>n;cout<<“k=”;cin>>k;for(i=1;i<=n;i++) st[i]=0;} void tipar(int p){int j;for(j=1;j<=p;j++)cout<<st[j]<<” “;cout<<endl;} int valid(int p){int i,ok;ok=1;for(i=1;i<p;i++)if(st[p]==st[i]) ok=0; return ok;} int solutie(int p){return (p==k);} void bkt(int p){int val;for (val=1;val<=n;val++){st[p]=val;if (valid(p))if(solutie(p))tipar(p);elsebkt(p+1);}} void main(){init();bkt(1);} {joscommentenable}

permutari

//permutari#include<iostream.h>int st[20],n; void init(){int i;cout<<“n=”;cin>>n;for(i=1;i<=n;i++) st[i]=0;} void tipar(int p){int j;for(j=1;j<=p;j++)cout<<st[j]<<” “;cout<<endl;} int valid(int p){int i,ok;ok=1;for(i=1;i<p;i++)if(st[p]==st[i]) ok=0;return ok;} int solutie(int p){return (p==n);} void bkt(int p){int val;for (val=1;val<=n;val++){st[p]=val;if (valid(p))if(solutie(p))tipar(p);elsebkt(p+1);}} void main(){init();bkt(1);} {joscommentenable}