Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("1.in");
  4. ofstream fout("1.out");
  5.  
  6. int n,s;//cardinaul multiii
  7. int X[21];//vectorul solutie
  8. int P[21];
  9.  
  10. void afisare()
  11. {
  12. for(int i=1; i<=n; i++)
  13. fout<<X[i];
  14. fout<<"\n";
  15. }
  16.  
  17. void back(int k,int sp)//sp=suma partiala
  18. {
  19. for(int i=0; i<=9; i++) //cifre!!!
  20. {
  21. if(!P[i])
  22. {
  23. X[k]=i;//plasez pe in poz. curenta (k)
  24. P[i]=1;
  25. sp=sp+X[k];//am pus
  26. if(X[1]!=0 && sp<=s)//pt eficienta
  27. if(k==n)//cond sol (sa fie puse toate n)
  28. {
  29. if(sp==s)
  30. afisare();//merg la afisare
  31. }
  32. else back(k+1,sp);//merg la poz urmatoare
  33. P[i]=0;
  34. sp=sp-X[k];//am scos
  35. }
  36. }
  37. }
  38. int main()
  39. {
  40. fin>>n>>s;
  41. back(1,0);
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement