关灯问题,问最少需要开关数(开关种类有多个)
高斯消元
/**
hdu 4200 bad writing
高斯消元+DFS
若满足n > 2D + 1,则矩阵的秩 >= n;故dfs的规模为2^(D+1)
*/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 101
int n,D,g[N][N],ans[N];
int row,col,res;
void dfs(int cur)
{
if(cur == n)
{
int i,j,c;
for(i = row - 1;i >= 0; --i)
{
c = g[i][n];
for (j = i+1; j < n;++j)
c ^= ans[j]&&g[i][j];
ans[i] = c;
}
c = 0;
for(i = 0;i < n; ++i)
c += ans[i]