Problem Link
#include <iostream>
using namespace std;
int main()
{
int t, n, k;
int arr[1001];
bool dp[1001][1024];
cin >> t;
while(t--)
{
cin >> n >> k;
for(int i = 0; i < n; i++)
{
cin >> arr[i];
}
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= 1023; j++)
{
dp[i][j] = false;
if(j == 0)
{
dp[i][j] = true;
}
else if(i > 0)
{
dp[i][j] = dp[i - 1][j] || dp[i - 1][j ^ arr[i - 1]];
}
}
}
int maxVal = k;
for(int i = 0; i <= 1023; i++)
{
if(dp[n][i])
{
maxVal = max(maxVal, k ^ i);
}
}
cout << maxVal << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int t, n, k;
int arr[1001];
bool dp[1001][1024];
cin >> t;
while(t--)
{
cin >> n >> k;
for(int i = 0; i < n; i++)
{
cin >> arr[i];
}
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= 1023; j++)
{
dp[i][j] = false;
if(j == 0)
{
dp[i][j] = true;
}
else if(i > 0)
{
dp[i][j] = dp[i - 1][j] || dp[i - 1][j ^ arr[i - 1]];
}
}
}
int maxVal = k;
for(int i = 0; i <= 1023; i++)
{
if(dp[n][i])
{
maxVal = max(maxVal, k ^ i);
}
}
cout << maxVal << endl;
}
return 0;
}
Comments
Post a Comment