fork(2) download
  1. #include<bits/stdc++.h>
  2. #define debug(x) cerr << #x << " = " << x << "\n";
  3. #define debug_v(x) cerr << #x << " ="; for(auto i : x) {cerr << " [" << i << "]";} cerr << "\n";
  4. using namespace std;
  5. using ll = long long;
  6. using ld = long double;
  7. const double PI = acos(-1);
  8. const int mod = 1e9 + 7;
  9. const int inf = 1e9 + 100;
  10. const ll inf64 = 1e18 + 100;
  11. void solve(){
  12. int n, k, answer = 0;
  13. cin >> n >> k;
  14. vector<int> a(n);
  15. for (int i = 0; i < n; i++){
  16. cin >> a[i];
  17. }
  18. for (int i = 1; i <= (1 << n); i++){
  19. if(__builtin_popcount(i) == k){
  20. int temp = 0;
  21. for (int j = 0; j < n; j++){
  22. if(i & (1 << j)){
  23. temp ^= a[j];
  24. }
  25. }
  26. answer = max(answer, temp);
  27. }
  28. }
  29. cout << answer << "\n";
  30. }
  31. int main(){
  32. ios_base::sync_with_stdio(false);
  33. cin.tie(0);
  34. cout.tie(0);
  35. cout << fixed << setprecision(20);
  36. int t;
  37. cin >> t;
  38. while(t--){
  39. solve();
  40. }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty