poj1681 Painter's Problem
题目描述:
和那道关灯差不多,求最少涂几次。
题解:
高消,然后深搜枚举自由元更新答案。
貌似这道题没卡贪心但是其他题基本都卡了。
比如$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的更多相关文章
- [POJ1681]Painter's Problem(高斯消元,异或方程组,状压枚举)
题目链接:http://poj.org/problem?id=1681 题意:还是翻格子的题,但是这里有可能出现自由变元,这时候枚举一下就行..(其实这题直接状压枚举就行) /* ━━━━━┒ギリギリ ...
- [Gauss]POJ1681 Painter's Problem
和POJ1222(分析)完全相同 题意也类似, 可以涂自己以及上下左右五个位置的颜色 问几次能全部涂色 不能输出inf 01方程组 用异或来求解就好了 ][]; // 增广矩阵 ]; // 解 ]; ...
- poj1681 Painter's Problem(高斯消元法,染色问题)
题意: 一个n*n 的木板 ,每个格子 都 可以 染成 白色和黄色,( 一旦我们对也个格子染色 ,他的上下左右都将改变颜色): 给定一个初始状态 , 求将 所有的 格子 染成黄色 最少需要染几次? ...
- POJ1681 Painter's Problem(高斯消元)
题目看似与线性方程组无关,但可以通过建模转化为线性方程组的问题. 对于一块砖,刷两次是没有必要的,我们令x=1表示刷了一次,x=0没有刷,一共有n*n个,所以相当于有n*n个未知量x. 定义aij表示 ...
- Painter's Problem poj1681 高斯消元法
Painter's Problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4420 Accepted: 2143 ...
- poj 1681 Painter's Problem
Painter's Problem 题意:给一个n*n(1 <= n <= 15)具有初始颜色(颜色只有yellow&white两种,即01矩阵)的square染色,每次对一个方格 ...
- POJ 1681 Painter's Problem 【高斯消元 二进制枚举】
任意门:http://poj.org/problem?id=1681 Painter's Problem Time Limit: 1000MS Memory Limit: 10000K Total ...
- OpenJudge 2813 画家问题 / Poj 1681 Painter's Problem
1.链接地址: http://bailian.openjudge.cn/practice/2813 http://poj.org/problem?id=1681 2.题目: 总时间限制: 1000ms ...
- Painter's Problem (高斯消元)
There is a square wall which is made of n*n small square bricks. Some bricks are white while some br ...
随机推荐
- 51nod 1133【贪心】
思路: 按照终点升序,然后遍历一下就好了: #include <bits/stdc++.h> using namespace std; typedef long long LL; cons ...
- 基于FBX SDK的FBX模型解析与加载 -(三)
http://blog.csdn.net/bugrunner/article/details/7229416 6. 加载Camera和Light 在FBX模型中除了几何数据外较为常用的信息可能就是Ca ...
- noip 2018 Day2 T1 旅行
暴力删边,暴力枚举 #include <bits/stdc++.h> using namespace std; #define MAXM 5010 inline int read() { ...
- Jquery | 基础 | 慕课网 | (*选择器)
原生JS var elements1 = document.getElementsByTagName('*'); JQ var elements2 = $("*"); <!D ...
- php分页例子实现读取mysql数据分页显示
以下代码是PHP分页案例,测试通过,主要是PHP+mysql实现分页,代码来处百度空间,有兴趣看的话可以了解一下PHP是如何分页的? <?php $link = mysql_connect(&q ...
- scikit-learning教程(二)统计学习科学数据处理的教程二
模型选择:选择估计量及其参数 得分和交叉验证的分数 如我们所看到的,每个估计者都会公开一种score可以判断新数据的拟合质量(或预测)的方法.越大越好. >>> >>&g ...
- A*算法、导航网格、路径点寻路对比(A-Star VS NavMesh VS WayPoint)
在Unity3d中,我们一般常用的寻路算法: 1.A*算法插件 与贪婪算法不一样,贪婪算法适合动态规划,寻找局部最优解,不保证最优解.A*是静态网格中求解最短路最有效的方法.也是耗时的算法,不 ...
- 在windows下编译出linux可执行程序
set GOARCH=amd64 set GOOS=linux go build xx.go 会生成一个没有后缀的xx二进制文件 将该文件放入linux系统某个文件夹下 赋予权限 chmod 777 ...
- let块级引起的闭包思考
因为es6在node中用的比较频繁,最近在按计划根据阮一峰的es6教程从头开始学习一遍, 第一步遇到的就是“看似非常熟悉”的let小伙伴,核心character如下: 即:let变量的作用域只在块内. ...
- pre-network android 网络优化预加载框架
网络优化是所有app开发中非常重要的一部分,如果将网络请求前置就是在点击跳转activity之前开始网络加载那么速度将会有质的提升.也就是网络预先加载框框架. 网络预加载框架,监听式网络前置加载框架- ...