#include <iostream>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <map>
//#include <time.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define LL long long using namespace std;
//using namespace __gnu_pbds; int dp[<<][]; int n; struct nodes
{
int x, y;
int operator - (const nodes &b)const
{
return max(abs(x - b.x) , abs(y - b.y));
}
}Point[]; int dfs(int statu,int cur)
{
if(dp[statu][cur] != -)
return dp[statu][cur];
if(statu == (<< (n+) )- && cur == )
return dp[statu][cur] = ;
dp[statu][cur] = 0x3f3f3f; for(int i = ; i <= n; i++)
{
if( ((statu >> i)&) == ) continue;
dp[statu][cur] = min(dp[statu][cur], dfs( statu|(<<i),i ) + (Point[cur]-Point[i]) );
} return dp[statu][cur];
} void solve()
{
memset(dp,-,sizeof(dp));
int row,col;
scanf("%d %d",&row,&col);
char ss[];
n = ;
for(int i = ; i <= row; i++)
{
scanf("%s",ss+);
for(int j = ; j <= col; j++)
if(ss[j] == 'x')
{
Point[].x = i;
Point[].y = j;
}
else if(ss[j] == 'g')
{
Point[++n].x = i;
Point[n].y = j;
}
}
int ans = dfs(,);
printf("%d\n",ans);
} int main(void)
{
int t,cnt = ;
scanf("%d",&t);
while(t--)
{
printf("Case %d: ",++cnt);
solve();
}
return ;
}

light oj 1057 状压dp TSP的更多相关文章

  1. light oj 1037 状压dp

    #include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...

  2. POJ3311 Hie with the Pie 【状压dp/TSP问题】

    题目链接:http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total ...

  3. Hie with the Pie(POJ3311+floyd+状压dp+TSP问题dp解法)

    题目链接:http://poj.org/problem?id=3311 题目: 题意:n个城市,每两个城市间都存在距离,问你恰好经过所有城市一遍,最后回到起点(0)的最短距离. 思路:我们首先用flo ...

  4. zoj 3471 Most Powerful(状压dp+Tsp问题+连续性问题)

    上来直接一波敲键盘,直接套Tsp问题的代码 然后WA 发现貌似这道题没有连续性. Tsp问题是一条路径,一个点到另一个点,多了一个限制,所以就需要加多一维 而这道题没有限制,也就是说那一维不需要加,我 ...

  5. poj 2288 Islands and Bridges (状压dp+Tsp问题)

    这道题千辛万苦啊! 这道题要涉及到当前点和前面两个点,那就设dp[state][i][j]为当前状态为state,当前点为i,前一个点为j 这个状态表示和之前做炮兵那题很像,就是涉及到三个点时,就多设 ...

  6. Light OJ 1011 - Marriage Ceremonies(状压DP)

    题目大意: 有N个男人,和N个女人要互相匹配,每个男人和每个女人有个匹配值. 并且匹配只能是1对1的. 问所有人都匹配完成,最大的匹配值是多少?   状压DP,暴力枚举就OK了, 这个题目略坑,因为他 ...

  7. poj3311 TSP经典状压dp(Traveling Saleman Problem)

    题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...

  8. HDU 5067 Harry And Dig Machine(状压DP)(TSP问题)

    题目地址:pid=5067">HDU 5067 经典的TSP旅行商问题模型. 状压DP. 先分别预处理出来每两个石子堆的距离.然后将题目转化成10个城市每一个城市至少经过一次的最短时间 ...

  9. 江南OJ 1151 - 还是晒太阳 - [状压DP]

    题目链接:校内OJ的题目,就不放链接了. PS.可以说是本次9月月赛唯一的一道有一定难度的题目了. 题解: 考虑状压DP,假设 $sta$ 是一个二进制数,代表当前 $n$ 个人有几个是在队伍里的,剩 ...

随机推荐

  1. web Magic报错 NoSuchMethodError NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter

    webMagic使用selenium的时候遇到报错: java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTime ...

  2. Hibernate之Inverse的用法

    在多的一端配置Inverse设置为true,来自动管理关系

  3. webstorm 初次上传代码到 远程gitlab中

    1. 在 公司搭建的gitlab网站,创建project,然后生成了 git的地址. 2.在 本地电脑上,打开 webstorm,要将已有的代码上传到 git网站,那么需要在webstrom编辑器的t ...

  4. (37)C#Linq

    https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/let-clause 一.定义 Linq(Lang ...

  5. 盒子阴影 box-shadow

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. IK分词器插件

    (1)源码 https://github.com/medcl/elasticsearch-analysis-ik  (2)releases https://github.com/medcl/elast ...

  7. MyBatis - Generator(MBG)

    前言 MyBatis Generator简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器, 可以快速的根据数据表自动生成Bean对象.Java接口及SqlMapper.xml配置文件. ...

  8. python Six 模块

    Six模块用于python2和python3的兼容 import six 官网链接:https://six.readthedocs.io/

  9. Linux文本编辑命令

    sort 排序工具,比较排序(根据字典排序) -t 指定分隔符(默认是空格) -k 指定第几域排序(默认第一域) -n 以数字大小排序 -r 逆向排序 -v 去掉重复行 -o 输出到文件中 -c 测试 ...

  10. java 测试时 程序的 运行时间

    检测一个JAVA程序的运行时间方法:long startTime = System.currentTimeMillis();//获取当前时间//doSomeThing();   //要运行的java程 ...