Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin("1.in");
- ofstream fout("1.out");
- int n,s;//cardinaul multiii
- int X[21];//vectorul solutie
- int P[21];
- void afisare()
- {
- for(int i=1; i<=n; i++)
- fout<<X[i];
- fout<<"\n";
- }
- void back(int k,int sp)//sp=suma partiala
- {
- for(int i=0; i<=9; i++) //cifre!!!
- {
- if(!P[i])
- {
- X[k]=i;//plasez pe in poz. curenta (k)
- P[i]=1;
- sp=sp+X[k];//am pus
- if(X[1]!=0 && sp<=s)//pt eficienta
- if(k==n)//cond sol (sa fie puse toate n)
- {
- if(sp==s)
- afisare();//merg la afisare
- }
- else back(k+1,sp);//merg la poz urmatoare
- P[i]=0;
- sp=sp-X[k];//am scos
- }
- }
- }
- int main()
- {
- fin>>n>>s;
- back(1,0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement