Advertisement
Korotkodul

mosh d

Feb 27th, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17. for (auto x: v) cout<<x<<' ';
  18. cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22. for (auto x: v) cout<<x<<' ';
  23. cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28. for (auto x: v) cv(x);
  29. cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33. for (bool x: v) cout<<x<<' ';
  34. cout<<"\n";
  35. }
  36. void cvs(vector <string> v){
  37. for (auto a: v){
  38. cout<<a<<"\n";
  39. }
  40. }
  41.  
  42. int t,n,m;
  43. string bin(int x){
  44. string r = "";
  45.  
  46. while (x > 0){
  47. r += x % 2 + '0';
  48. x /= 2;
  49. }
  50. reverse(r.begin(), r.end());
  51. while (r.size() < n){
  52. r = '0' + r;
  53.  
  54. }
  55. return r;
  56. }
  57.  
  58. int main()
  59. {
  60. ios::sync_with_stdio(0);
  61. cin.tie(0);
  62. cout.tie(0);
  63.  
  64. cin>>t;
  65.  
  66. for (int act=0;act<t;++act){
  67. cin>>n>>m;
  68. vector <int> lock(n);
  69. for (int i = 0 ; i< n;++i) cin>>lock[i];
  70. vector <vector <int> > box(m, vector <int> (n));
  71. for (int i = 0 ; i < m;++i){
  72. for (int j=0;j<n;++j) cin>>box[i][j];
  73. }
  74. //все варианты раскрытия коробочек
  75. int S = 2e9;
  76. vector <int> ans(m);
  77. for (int var = 0; var < (1 << n); ++var){
  78. int Svar=0;
  79. vector <int> ansVar(m);
  80. vector <int> cost(m, 2e9);
  81. string open = bin(var);
  82. for (int i=0;i<n;++i){
  83. if (open[i] == '1'){
  84. Svar += lock[i];
  85. }
  86. }
  87. for (int good = 0; good < m; ++good){
  88. pii bst = {2e9, -1};
  89. for (int shop = 0; shop < n; ++shop){
  90. if (open[shop] == '0') continue;
  91. if (cost[good] > box[good][shop]){
  92. cost[good] = box[good][shop];
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement