Advertisement
a53

PartitiiMultime3

a53
Nov 30th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. ifstream fin("partitiimultime3.in");
  5. ofstream fout("partitiimultime3.out");
  6.  
  7. int n, m, Max[21], mat[21][21], c2, cnt[21];
  8. char rasp[81];
  9. inline void afisare()
  10. {
  11. if(Max[n]==n/m)
  12. {
  13. c2 = -1;
  14. for(int i = 1; i <= Max[n]; ++i, rasp[++c2] = '*')
  15. for(int j = 1; j <= cnt[i] && cnt[i]==m; ++j)
  16. if(mat[i][j] < 10)
  17. rasp[++c2] = mat[i][j] + '0';
  18. else
  19. rasp[++c2] = mat[i][j] / 10 + '0', rasp[++c2] = mat[i][j] % 10 + '0';
  20. rasp[++c2] = '\0';
  21. if(rasp[0]!='*' && rasp[strlen(rasp)-2]!='*')
  22. fout << rasp << '\n';
  23. }
  24. }
  25.  
  26. inline void back(int const& k)
  27. {
  28. Max[k] = Max[k - 1];
  29. for (int i = 1; i <= Max[k - 1] + 1; ++i)
  30. {
  31. mat[i][++cnt[i]] = k;
  32. if (i > Max[k])
  33. Max[k] = i;
  34. if(k == n)
  35. afisare();
  36. else
  37. back(k + 1);
  38. mat[i][--cnt[i]];
  39. }
  40. }
  41.  
  42. int main()
  43. {
  44. fin >> n>>m;
  45. if(n%m)
  46. {
  47. fout<<"IMPOSIBIL";
  48. return 0;
  49. }
  50. back(1);
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement