题意:给你n行长度为m的01串(n<15,m<100) .每次只能走一步,要将所有的1变为零,问最少的步数,注意从左下角开始,每次要将一层清完才能走到上一层,每次只有在第一列或者最后一列才能往上走一层,否则只能左右移动. 题解:由于清完当前层才能继续上一层,所以必然存在一个递推关系.先递推预处理,然后输出ans即可.用far来存最远的那个1,如果这层没有1,假设有一个,令其距离为1 具体看代码注释吧. 坑:没考虑没有1以及只有1层的情况 #define _CRT_SECURE_NO_WARNI…
http://codeforces.com/contest/812/problem/B [题意] 有一个n*m的棋盘,每个小格子有0或1两种状态,现在要把所有的1都变成0,问最少的步数是多少?初始位置在左下角,只有把下面一层的1都变成0后才可以到上一层,只有在每层的最右边和最左边可以向上走(up),否则只能左右移动(left or right).只要经过1,就可以把1变成0,只要把最后一个1,就可以立即停止操作. [Accepted] #include <iostream> #include…
812B - Sagheer, the Hausmeister 思路: 搜索: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 20 #define maxm 105 #define INF 0x7fffffff ],num[maxn],ans=INF,k,sum[maxn],…
题目链接:http://codeforces.com/problemset/problem/812/B B. Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Some people leave the lights at their workplaces on when they…
B. Sagheer, the Hausmeister time limit per test  1 second memory limit per test  256 megabytes   Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all studen…
Sagheer, the Hausmeister CodeForces - 812B 题意:有一栋楼房,里面有很多盏灯没关,为了节约用电小L决定把这些灯都关了. 这楼有 n 层,最左边和最右边有楼梯.每一层有 m 个房间排成一排.这栋楼可以被表示成一个 n 行 m + 2 列的矩阵,其中每行第一个和最后一个格点表示楼梯, 剩余 m 个格点表示房间. 现在小L在最底层的最左边楼梯,他想要关掉所有的灯.他每次可以走到相邻的房间,如果在楼梯口可以上下楼梯.他打算关掉所有开着的灯,在他没有将一层的所有灯…
B. Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeiste…
http://codeforces.com/problemset/problem/812/B B. Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Some people leave the lights at their workplaces on when they leav…
题目传送门 /* 记忆化搜索(DP+DFS):dp[i][j] 表示第i到第j个字符,最少要加多少个括号 dp[x][x] = 1 一定要加一个括号:dp[x][y] = 0, x > y; 当s[x] 与 s[y] 匹配,则搜索 (x+1, y-1); 否则在x~y-1枚举找到相匹配的括号,更新最小值 */ #include <cstdio> #include <algorithm> #include <cmath> #include <iostream&…
codeforces 812E Sagheer and Apple Tree 题意 一棵带点权有根树,保证所有叶子节点到根的距离同奇偶. 每次可以选择一个点,把它的点权删除x,它的某个儿子的点权增加x.点权中途中不能为负.如果选中的是叶子节点,则只删除它的点权. 两个人玩博弈,后手可以先交换两个点点权,问有多少种方法使得他必胜? 题解 观察一下可以发现,把和叶节点同奇偶的那些点拉出来,相比nim博弈多了一种操作:增加一些石子在某堆.不过本质不会有什么变化,因为如果A选择增加,B可以选择减少相同的…