Codeforces 812 B Sagheer, the Hausmeister
来源:互联网 发布:网络通信链路有哪些 编辑:程序博客网 时间:2024/05/22 04:37
题目链接:http://codeforces.com/contest/812/problem/B
题意:题目中的意思就是说有一栋楼有n层每层有m个房间,两边各有一个楼梯,上下楼梯需要的时间是1分钟,从一个房间走到相邻的房间的时间是1分钟,这栋楼里有一些房间的灯是亮着的,你需要把这些灯给关掉,问你最少需要的时间是多少,你每次都是从最下面那层的左边出发,最后不需要回到起点。
题解:其实直接dfs所有的状态就好了(详细还是看代码)
#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <map>#include <set>#include <algorithm>#define inf 0x3f3f3f3f#define LL long longusing namespace std;int n, m;char mapp[20][110];int dfs(int cnt, int pos, int temp) {//cnt表示楼层,pos表示是哪边的楼梯,temp表示的是上楼要走多少步 if (cnt < 0) { return 0; } int ans = 0; if (pos) { for (int i = m+2; i >= 0; i--) { if (mapp[cnt][i] == '1') { ans += pos - i + temp; pos = i; temp = 0; } } } else { for (int i = 0; i < m+2; i++) { if (mapp[cnt][i] == '1') { ans += i - pos + temp; pos = i; temp = 0; } } } ans += min(dfs(cnt - 1, 0, temp + pos + 1), dfs(cnt - 1, m + 1, temp + m + 2 - pos)); return ans;}int main() { cin.sync_with_stdio(false); while (cin >> n >> m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m + 2; j++) { cin >> mapp[i][j]; } } cout << dfs(n-1,0,0) << endl; } return 0;}
阅读全文
2 0
- Codeforces 812B-Sagheer, the Hausmeister
- Codeforces 812B Sagheer, the Hausmeister[dp]
- codeforces 812 B Sagheer, the Hausmeister(枚举)
- Codeforces 812 B Sagheer, the Hausmeister
- codeforces 812B Sagheer, the Hausmeister dp
- codeforces 812b Sagheer, the Hausmeister
- codeforces Sagheer, the Hausmeister 812B
- Codeforces 812B-Sagheer, the Hausmeister
- Sagheer, the Hausmeister CodeForces
- Sagheer, the Hausmeister CodeForces
- B. Sagheer, the Hausmeister
- Codeforecs 812B Sagheer, the Hausmeister DP
- CF 812B Sagheer, the Hausmeister
- Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
- Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
- Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
- CodeFroces 812B Sagheer, the Hausmeister(BFS)
- Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister dfs深度优先搜索
- 新手 centos 7 wget下载oracle官网的jdk8安装教程
- hdu 2092 水题还是要有套路的
- H5识别二维码问题
- github上传本地代码
- 数据结构 二叉树(binarytree)的实现
- Codeforces 812 B Sagheer, the Hausmeister
- 如果看了此文你还不懂傅里叶变换,那就过来掐死我吧【完整版】
- python 折行的正确姿势
- xml解析的pull解析示例
- Win7 PHP v5.6 成功安装Imagick库
- linux下的"BusHound"——usbmon
- iphone手机fiddler抓包
- 开启ssh
- Struts2入门