Advertisement
a53

subsets

a53
Jun 2nd, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int t[12], a[12], n;
  5.  
  6. int main()
  7. {
  8. int i, s[4], cnt;
  9. cin >> n;
  10. for (i = 1; i <= n; i++)
  11. cin >> t[i];
  12.  
  13. /// generarea tuturor configuratiilor de 0,1,2,3 de lungime n
  14. cnt = 0;
  15. while (a[0] == 0)
  16. {
  17. /// calcul sume
  18. s[0] = s[1] = s[2] = s[3] = 0;
  19. for (i = 1; i <= n; i++)
  20. s[a[i]] += t[i];
  21. if (s[1] == s[2] && s[2] == s[3] && s[1] > 0)
  22. cnt++;
  23.  
  24. /// urmatoarea configuratie
  25. for (i = n; a[i] == 3; i--)
  26. a[i] = 0;
  27. a[i]++;
  28. }
  29. cnt /= 6;
  30. cout << cnt << "\n";
  31. return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement