题目描述:

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

题解:

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

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

比如$Usaco09Nov$的$lights$

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. const int N = ;
  6. int t,n,dx[]={-,,,},dy[]={,,,-};
  7. char mp[N][N];
  8. bool check(int x,int y)
  9. {
  10. return x>=&&x<=n&&y>=&&y<=n;
  11. }
  12. int _id(int x,int y)
  13. {
  14. return (x-)*n+y;
  15. }
  16. int a[N*N][N*N],ans;
  17. void gs()
  18. {
  19. for(int l1=;l1<=n*n;l1++)
  20. {
  21. int tmp = l1;
  22. while(tmp<=n*n&&!a[tmp][l1])tmp++;
  23. if(tmp>n*n)continue;
  24. if(tmp!=l1)
  25. for(int i=l1;i<=n*n+;i++)swap(a[tmp][i],a[l1][i]);
  26. for(int i=;i<=n*n;i++)if(a[i][l1]&&i!=l1)
  27. for(int j=l1;j<=n*n+;j++)a[i][j]^=a[l1][j];
  28. }
  29. }
  30. void dfs(int dep,int now)
  31. {
  32. if(now>=ans)return ;
  33. if(!dep){ans=now;return ;}
  34. if(a[dep][dep])
  35. {
  36. dfs(dep-,now+a[dep][n*n+]);
  37. }else
  38. {
  39. if(a[dep][n*n+])return ;
  40. dfs(dep-,now);
  41. for(int i=dep-;i>=;i--)if(a[i][dep])
  42. a[i][n*n+]^=;
  43. dfs(dep-,now+);
  44. for(int i=dep-;i>=;i--)if(a[i][dep])
  45. a[i][n*n+]^=;
  46. }
  47. }
  48. int main()
  49. {
  50. scanf("%d",&t);
  51. while(t--)
  52. {
  53. memset(a,,sizeof(a));
  54. scanf("%d",&n);
  55. for(int i=;i<=n;i++)
  56. scanf("%s",mp[i]+);
  57. for(int i=;i<=n;i++)for(int j=;j<=n;j++)
  58. {
  59. int u = _id(i,j);
  60. a[u][u]=;
  61. for(int k=;k<;k++)
  62. {
  63. int x = i+dx[k],y = j+dy[k];
  64. if(check(x,y))
  65. a[u][_id(x,y)]=;
  66. }
  67. a[u][n*n+]=(mp[i][j]=='w');
  68. }
  69. gs();
  70. ans=0x3f3f3f3f;
  71. dfs(n*n,);
  72. if(ans==0x3f3f3f3f)puts("inf");
  73. else printf("%d\n",ans);
  74. }
  75. return ;
  76. }

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. 51nod 1133【贪心】

    思路: 按照终点升序,然后遍历一下就好了: #include <bits/stdc++.h> using namespace std; typedef long long LL; cons ...

  2. 基于FBX SDK的FBX模型解析与加载 -(三)

    http://blog.csdn.net/bugrunner/article/details/7229416 6. 加载Camera和Light 在FBX模型中除了几何数据外较为常用的信息可能就是Ca ...

  3. noip 2018 Day2 T1 旅行

    暴力删边,暴力枚举 #include <bits/stdc++.h> using namespace std; #define MAXM 5010 inline int read() { ...

  4. Jquery | 基础 | 慕课网 | (*选择器)

    原生JS var elements1 = document.getElementsByTagName('*'); JQ var elements2 = $("*"); <!D ...

  5. php分页例子实现读取mysql数据分页显示

    以下代码是PHP分页案例,测试通过,主要是PHP+mysql实现分页,代码来处百度空间,有兴趣看的话可以了解一下PHP是如何分页的? <?php $link = mysql_connect(&q ...

  6. scikit-learning教程(二)统计学习科学数据处理的教程二

    模型选择:选择估计量及其参数 得分和交叉验证的分数 如我们所看到的,每个估计者都会公开一种score可以判断新数据的拟合质量(或预测)的方法.越大越好. >>> >>&g ...

  7. A*算法、导航网格、路径点寻路对比(A-Star VS NavMesh VS WayPoint)

    在Unity3d中,我们一般常用的寻路算法:   1.A*算法插件   与贪婪算法不一样,贪婪算法适合动态规划,寻找局部最优解,不保证最优解.A*是静态网格中求解最短路最有效的方法.也是耗时的算法,不 ...

  8. 在windows下编译出linux可执行程序

    set GOARCH=amd64 set GOOS=linux go build xx.go 会生成一个没有后缀的xx二进制文件 将该文件放入linux系统某个文件夹下 赋予权限 chmod 777 ...

  9. let块级引起的闭包思考

    因为es6在node中用的比较频繁,最近在按计划根据阮一峰的es6教程从头开始学习一遍, 第一步遇到的就是“看似非常熟悉”的let小伙伴,核心character如下: 即:let变量的作用域只在块内. ...

  10. pre-network android 网络优化预加载框架

    网络优化是所有app开发中非常重要的一部分,如果将网络请求前置就是在点击跳转activity之前开始网络加载那么速度将会有质的提升.也就是网络预先加载框框架. 网络预加载框架,监听式网络前置加载框架- ...