Calculate the basis of the linear space by using Gaussian deyuan, that is, the rank of the matrix.
Code:
#include #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define CHECKTIME() printf(%.2lf, (double)clock() / CLOCKS_PER_SEC)typedef pair
pii;typedef long long llong;typedef pair
pll;#define mkp make_pair#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); ++it)/*************** Program Begin **********************/class MixingColors {public:int minColors(vector
colors) {int res = 0;int n = colors.size();bool used[55];memset(used, 0, sizeof(used));for (int i = 31; i >= 0; i--) {int pivot = 0;for (int j = 0; j < n; j++) {if (used[j]) {continue;}if ((colors[j] >> i) & 0x1) {if (!pivot) {pivot = colors[j];used[j] = true;++res;} else {colors[j] ^= pivot;}}}}return res;}};/************** Program End ************************/