poj 2965 枚举+DFS】的更多相关文章

The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25343   Accepted: 9786   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
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 //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…
题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#problem/B 题意: 就是把题目中给出的状态图,全部翻转成 ---- ---- ---- ----状态 翻转: 每次翻转一个,那么它所在的行和列都要翻转 问最小翻转次数,同时输出翻转路径. 算法: 暴力 + 枚举 + dfs 思路: 可以证明每个把手要么翻转,要么不翻转,那么从左到右,从上到下依次枚…
链接:poj 2965 题意:给定一个4*4矩阵状态,代表门的16个把手.'+'代表关,'-'代表开.当16个把手都为开(即'-')时.门才干打开,问至少要几步门才干打开 改变状态规则:选定16个把手中的随意一个,能够改变其本身以及同行同列的状态(即若为开,则变为关,若为关,则变为开),这一次操作为一步. 分析:这题与poj 1753思路差点儿相同,每一个把手最多改变一次状态, 全部整个矩阵最多改变16次状态 思路:直接dfs枚举全部状态,直到找到目标状态 可是要打印路径,全部应在dfs时记录路…
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+'记为1, '-'记为0 1. 从(1, 1)走到(4, 4),每一点DFS两次(改点反转或不反转):used记录反转的位置 详细解释:http://poj.org/showmessage?message_id=346723 2. 比较巧妙的解法:抓住'+'位置反转,'-'位置相对不反转的特点,从状…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286   Accepted: 8603   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
id=2965">The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18080   Accepted: 6855   Special Judge Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a…
POJ.3172 Scales (DFS) 题意分析 一开始没看数据范围,上来直接01背包写的.RE后看数据范围吓死了.然后写了个2^1000的DFS,妥妥的T. 后来想到了预处理前缀和的方法.细节以注释的方式给出. 代码总览 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <s…
题目链接: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了:这样每次只需要…