UESTC 1852 Traveling Cellsperson
Traveling Cellsperson
64-bit integer IO format: %lld Java class name: Main
You have solved every problem from Project Euler in your head. Now it is time for a problem you might have heard of,namely The Traveling Salesperson, whose decision version is NP-complete. We consider the Traveling Salesperson problem in a 2D rectangular grid where every cell can be reached from their neighboring cells (up,down, left and right) and you can visit a cell as many times as you like (though, most of the cells aren't that interesting, so you might prefer not to visit them a lot).
Input
The first line of the input consists of a single integer T, the number of test cases. Then follow two integers X and Y , marking the width and height of the grid, respectively. Then follow Y lines with X characters, where the character 'C' is a cell and the character 'S' is the starting point.
0 < T <= 50
0 < X <= 100
0 < Y <= 100
All characters in a test case are 'C', except for exactly one, which is 'S'.
Output
For each test case, output the minimum number of steps required to make a full roundtrip of the grid, starting and ending at S, and visiting each cell at least once.
Since you realize that this won't lead anywhere, finish off the output with "LOL"(without quotes) on a line of its own (one per run, not per test case).
Sample Input
1
4 4
CCCC
CCCC
CSCC
CCCC
Sample Output
16
LOL
Source
IDI Open 2013 Programming Contest
#include <iostream>
#include <cstring> #include <cstdio> using namespace std; char str[110]; int main() |
* This source code was highlighted by YcdoiT. ( style: Codeblocks )
UESTC 1852 Traveling Cellsperson的更多相关文章
- Traveling by Stagecoach(POJ 2686)
原题如下: Traveling by Stagecoach Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4494 Ac ...
- ACM:UESTC - 649 括号配对问题 - stack
UESTC - 649 括号配对问题 Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu ...
- Traveling in Blade & Soul
Traveling in Blade & Soul Walking is too simple. Having trained their physics and spirits for ye ...
- UESTC 1015 Lweb and pepper --前,后缀最值
题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...
- UESTC 1851 Kings on a Chessboard
状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...
- UESTC 30 最短路,floyd,水
最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Statu ...
- uestc oj 1218 Pick The Sticks (01背包变形)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 给出n根木棒的长度和价值,最多可以装在一个长 l 的容器中,相邻木棒之间不允许重叠,且两边上的木棒,可 ...
- uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...
- Traveling by Stagecoach 状态压缩裸题
Traveling by Stagecoach dp[s][v] 从源点到达 v,状态为s,v的最小值. for循环枚举就行了. #include <iostream> #inclu ...
随机推荐
- sublime编写markdown文件中Ctrl+B的作用
今天,手残,用markdown编辑是按了Ctrl+B,结果发现直接在同一文件夹目录下编译生成了html文件,之前都是Alt+m,可以直接预览,可是后来由于系统更新还是什么,Alt+m只会在用户目录(而 ...
- androidstudio 之 svn配置 汇总
http://www.cnblogs.com/shaocm/p/4182380.html https://www.zhihu.com/question/32298079 http://www.it16 ...
- MOOCULUS微积分-2: 数列与级数学习笔记 4. Alternating series
此课程(MOOCULUS-2 "Sequences and Series")由Ohio State University于2014年在Coursera平台讲授. PDF格式教材下载 ...
- SampleDateFormat进行日期格式化
我们生成的日期 ,可能不是我们想要的格式,这时候,就要用到SampleDateFormat类的format方法转换一下, SampleDateFormat是java.text包下的一个常用日期类 这个 ...
- IOS - 打印COOKIE中的 CRFSToken
NSHTTPCookie 在iOS中使用NSHTTPCookie类封装一条cookie,通过NSHTTPCookie的方法读取到cookie的通用属性. - (NSUInteger)version; ...
- XML学习笔记
XML学习笔记 第一部分:XML简介 我们经常可以听到XML.HTML.XHTML这些语言,后两者比较清楚,一直不是很明白XML是什么,这里做一个总结. XML(eXtensible Markup L ...
- Eclipse自动补全+常用快捷键
一,Eclipse自动补全增强方法 在Eclipse中,从Window -> preferences -> Java -> Editor -> Content assist - ...
- 关于主机FTP连接不上,无法列出目录,列表错误,上传速度慢,掉速的解决办法
FTP是一种文件传输协议,它支持两种模式: 一种方式叫做Standard (也就是 Active,主动方式), 一种是 Passive (也就是PASV,被动方式). Standard模式 FTP的客 ...
- easyUI datagrid editor扩展dialog
easyUI datagrid简单使用:着重两点1.editor对象的click事件:2.将dialog窗体内的值填写到当前正编辑的单元格内 <!DOCTYPE html> <htm ...
- 9月9日HTML上午表单元素2(框架、样式表)
五.框架 1.frameset是双标签框架集,如果使用框架集,当前页面不能有body. frameset属性:①cols代表左右拆分.cols=“300,*”表示左边框架宽300,右边宽剩余的宽度.* ...