题目描述:

和那道关灯差不多,求最少涂几次。

题解:

高消,然后深搜枚举自由元更新答案。

貌似这道题没卡贪心但是其他题基本都卡了。

比如$Usaco09Nov$的$lights$

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
int t,n,dx[]={-,,,},dy[]={,,,-};
char mp[N][N];
bool check(int x,int y)
{
return x>=&&x<=n&&y>=&&y<=n;
}
int _id(int x,int y)
{
return (x-)*n+y;
}
int a[N*N][N*N],ans;
void gs()
{
for(int l1=;l1<=n*n;l1++)
{
int tmp = l1;
while(tmp<=n*n&&!a[tmp][l1])tmp++;
if(tmp>n*n)continue;
if(tmp!=l1)
for(int i=l1;i<=n*n+;i++)swap(a[tmp][i],a[l1][i]);
for(int i=;i<=n*n;i++)if(a[i][l1]&&i!=l1)
for(int j=l1;j<=n*n+;j++)a[i][j]^=a[l1][j];
}
}
void dfs(int dep,int now)
{
if(now>=ans)return ;
if(!dep){ans=now;return ;}
if(a[dep][dep])
{
dfs(dep-,now+a[dep][n*n+]);
}else
{
if(a[dep][n*n+])return ;
dfs(dep-,now);
for(int i=dep-;i>=;i--)if(a[i][dep])
a[i][n*n+]^=;
dfs(dep-,now+);
for(int i=dep-;i>=;i--)if(a[i][dep])
a[i][n*n+]^=;
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%s",mp[i]+);
for(int i=;i<=n;i++)for(int j=;j<=n;j++)
{
int u = _id(i,j);
a[u][u]=;
for(int k=;k<;k++)
{
int x = i+dx[k],y = j+dy[k];
if(check(x,y))
a[u][_id(x,y)]=;
}
a[u][n*n+]=(mp[i][j]=='w');
}
gs();
ans=0x3f3f3f3f;
dfs(n*n,);
if(ans==0x3f3f3f3f)puts("inf");
else printf("%d\n",ans);
}
return ;
}

poj1681 Painter's Problem的更多相关文章

  1. [POJ1681]Painter's Problem(高斯消元,异或方程组,状压枚举)

    题目链接:http://poj.org/problem?id=1681 题意:还是翻格子的题,但是这里有可能出现自由变元,这时候枚举一下就行..(其实这题直接状压枚举就行) /* ━━━━━┒ギリギリ ...

  2. [Gauss]POJ1681 Painter's Problem

    和POJ1222(分析)完全相同 题意也类似, 可以涂自己以及上下左右五个位置的颜色 问几次能全部涂色 不能输出inf 01方程组 用异或来求解就好了 ][]; // 增广矩阵 ]; // 解 ]; ...

  3. poj1681 Painter's Problem(高斯消元法,染色问题)

    题意: 一个n*n 的木板 ,每个格子 都 可以 染成 白色和黄色,( 一旦我们对也个格子染色 ,他的上下左右都将改变颜色): 给定一个初始状态 , 求将 所有的 格子 染成黄色 最少需要染几次?  ...

  4. POJ1681 Painter's Problem(高斯消元)

    题目看似与线性方程组无关,但可以通过建模转化为线性方程组的问题. 对于一块砖,刷两次是没有必要的,我们令x=1表示刷了一次,x=0没有刷,一共有n*n个,所以相当于有n*n个未知量x. 定义aij表示 ...

  5. Painter's Problem poj1681 高斯消元法

    Painter's Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4420   Accepted: 2143 ...

  6. poj 1681 Painter's Problem

    Painter's Problem 题意:给一个n*n(1 <= n <= 15)具有初始颜色(颜色只有yellow&white两种,即01矩阵)的square染色,每次对一个方格 ...

  7. POJ 1681 Painter's Problem 【高斯消元 二进制枚举】

    任意门:http://poj.org/problem?id=1681 Painter's Problem Time Limit: 1000MS   Memory Limit: 10000K Total ...

  8. OpenJudge 2813 画家问题 / Poj 1681 Painter's Problem

    1.链接地址: http://bailian.openjudge.cn/practice/2813 http://poj.org/problem?id=1681 2.题目: 总时间限制: 1000ms ...

  9. Painter's Problem (高斯消元)

    There is a square wall which is made of n*n small square bricks. Some bricks are white while some br ...

随机推荐

  1. Swift3.0 UICollectionView 删除,拖动

    UICollectionView实现了一下常见的新闻分类.  附有效果图 近期一直在深入学习swift,实现了CollectionView item的头东与删除,用的都是系统的一些函数方法,看起来比较 ...

  2. ObjectARX学习笔记

    http://blog.csdn.net/jangdong/article/category/1642265/3 http://blog.csdn.net/u011331383/article/cat ...

  3. python __builtins__ help类 (32)

    32.'help', 接收对象作为参数,更详细地返回该对象的所有属性和方法 class _Helper(builtins.object) | Define the builtin 'help'. | ...

  4. 解决 Xshell 连接出现 The remote SSH server rejected X11 forwarding request 问题

    问题描述 使用 Xshell 5 首次连接虚拟机 CentOS 7.6 出现这样的提示: WARNING! The remote SSH server rejected X11 forwarding ...

  5. B.华华教月月做数学

    链接:https://ac.nowcoder.com/acm/contest/392/B 题意: 找到了心仪的小姐姐月月后,华华很高兴的和她聊着天.然而月月的作业很多,不能继续陪华华聊天了.华华为了尽 ...

  6. Educational Codeforces Round 24 E

    Vova again tries to play some computer card game. The rules of deck creation in this game are simple ...

  7. April Fools Contest 2017 F

    Description You are developing a new feature for the website which sells airline tickets: being able ...

  8. Package 和 import 语句

  9. C. Molly's Chemicals 暴力 + 统计技巧

    http://codeforces.com/contest/776/problem/C 一开始做的时候,就发现是预处理前缀和,然后对于每一个前缀和,如果他能成为一个贡献,就是能和前面的某些段 组合成和 ...

  10. 使用VMwaver 克隆CentOS 6.9网卡配置报错

    报错信息: 克隆完成之后,使用的是NAT模式,进入系统之后有IP地址也可以ping外网,但是没有ifcfg-eth0这个文件,使用setup命令配置网卡时报以下错误: 待解决-