Fliptile(枚举+DFS)】的更多相关文章

题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#problem/B 题意: 就是把题目中给出的状态图,全部翻转成 ---- ---- ---- ----状态 翻转: 每次翻转一个,那么它所在的行和列都要翻转 问最小翻转次数,同时输出翻转路径. 算法: 暴力 + 枚举 + dfs 思路: 可以证明每个把手要么翻转,要么不翻转,那么从左到右,从上到下依次枚…
Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ 15; 1 ≤ N ≤ 15) of square tiles, each of which is colored black…
Problem Description Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ 15; 1 ≤ N ≤ 15) of square tiles, each of whi…
题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 $ , $ 1 <= M <= 300$ 解法1:由于行数不多,二进制枚举选出的行数,时间复杂度为O((1<<16)*K), 其中K即为判断选出的行数是否存在相同的列中有重复的1: 优化:将1状压即可,这样300的列值,压缩在int的32位中,使得列数“好像”小于10了:这样每次只需要…
Problem UVA818-Cutting Chains Accept:393  Submit:2087 Time Limit: 3000 mSec  Problem Description What a find! Anna Locke has just bought several links of chain some of which may be connected. They are made from zorkium, a material that was frequently…
题目链接:http://poj.org/problem?id=3279 题目大意:有一个n*m的格子,每个格子都有黑白两面(0表示白色,1表示黑色).我们需要把所有的格子都反转成黑色,每反转一个格子,它上下左右的格子都会跟着反转.请求出用最小步数完成反转时每个格子反转的次数.有多个解时,输出字典序最小的一组. 解题思路:只要枚举第一行的2^m种情况,如果一个位置上一行是1,那这个位置一定要反转,因为只有这一行能改变上一行,所以每一行的状态都是由前一行决定的.只要最后判断最后一行是不是都是0即可,…
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40632   Accepted: 17647 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the…
又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ czy Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1360    Accepted Subm…
思路: 枚举+搜一下+判个重 ==AC //By SiriusRen #include <set> #include <cstdio> using namespace std; int a[8][8],xx[]={1,-1,0,0},yy[]={0,0,1,-1}; set<int>s; bool check(int x,int y){ return x>0&&x<6&&y>0&&y<6; } vo…
题目链接:Fliptile 题目大意 有一个01矩阵,每一次翻转(0->1或者1->0)一个元素,就会把与他相邻的四个元素也一起翻转.求翻转哪些元素能用最少的步骤,把矩阵变成0矩阵. 思路 假设确定了第一行的状态,那么第二行需要翻转的所有元素都能确定(上一行如果是1就必须翻转).因此对于所有第一排的情况,往下递推需要翻转的元素,最后判断最后一行如果全为0则满足条件,记录步骤最少的情况. 题解 #include <iostream> #include <cstring>…