fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define all(a) a.begin(), a.end()
  4. #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  5. #define pb push_back
  6. #define ppi pair<int,pair<int,int>>
  7. //#define int int64_t
  8.  
  9. using namespace std;
  10. // /\_/\
  11. // (= ._.)
  12. // / > \>
  13. // encouraging cat
  14. const int INF = 10000000000000000;
  15. //const int mod = 1000000007;
  16. const int mod = 998244353;
  17. const int MAXN = 200005;
  18. //ifstream fin('xor.in');
  19. //ofstream fout('xor.out');
  20.  
  21. signed main()
  22. {
  23. int n,m,x,y;
  24. cin >> n >> m >> x >> y;
  25. vector<string> combo(n);
  26. vector<int> count(n,0);
  27. for (int i = 0;i < n;i++)
  28. {
  29. cin >> combo[i];
  30. for (int j = 0;j < m;j++)
  31. {
  32. if (combo[i][j] == '1')
  33. {
  34. count[i]++;
  35. }
  36. }
  37. }
  38. int global_res = 0;
  39. for (int b = 0;b < pow(2,n);b++)
  40. {
  41. int nbset = 0;
  42. int total_combo = 0;
  43. vector<int> cnt(m,0);
  44. for (int i = 0;i < n;i++)
  45. {
  46. if (b & (1 << i))
  47. {
  48. nbset++;
  49. total_combo += count[i];
  50. }
  51. }
  52. int res = total_combo -(nbset * x) - (m * y);
  53. global_res = max(res, global_res);
  54. }
  55. cout << global_res << '\n';
  56. return 0;
  57. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
0