1057 - Collecting Gold (状态压缩DP)
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #include<cmath>
- #include<queue>
- #include<vector>
- #include<map>
- using namespace std;
- typedef long long LL;
- const int INF = 1e9+;
- const int MAXN = ;
- int dp[MAXN][], m, n, k;///状态,当前所在的位置
- char maps[][];
- struct Point
- {
- int x, y;
- }P[], Star;
- int GetLen(Point A, Point B)
- {
- int len = min(abs(A.x-B.x),abs(A.y-B.y));
- len += max(abs(A.x-B.x),abs(A.y-B.y)) - len;
- return len;
- }
- int DFS(int sta,int x)///状态, 现在所在的位置
- {
- if(dp[sta][x] != -) return dp[sta][x];
- dp[sta][x] = INF;
- for(int i=; i<k; i++)
- {
- if( (sta&(<<i)) && i != x)
- {
- dp[sta][x] = min(dp[sta][x], DFS(sta-(<<x), i)+GetLen(P[x],P[i]));
- }
- }
- // printf("dp[%d][%d] = %d\n", sta, x, dp[sta][x]);
- return dp[sta][x];
- }
- int main()
- {
- int T, cas = ;
- scanf("%d", &T);
- while(T --)
- {
- scanf("%d %d",&n, &m);
- k = ;
- memset(dp, -, sizeof(dp));
- for(int i=; i<n; i++)
- {
- scanf("%s", maps[i]);
- for(int j=; j<m; j++)
- {
- if(maps[i][j] == 'g')
- P[k].x = i, P[k++].y = j;
- if(maps[i][j] == 'x')
- Star.x = i, Star.y = j;
- }
- }
- for(int i=; i<k; i++)
- {
- int sta = <<i;
- dp[sta][i] = GetLen(Star, P[i]);
- }
- int ans = INF, Lim = (<<k)-;
- for(int i=; i<k; i++)///最后停留的位置
- ans = min(ans,DFS(Lim,i)+GetLen(Star,P[i]));
- if(k == )
- ans = ;
- printf("Case %d: %d\n", cas ++, ans);
- }
- return ;
- }
1057 - Collecting Gold (状态压缩DP)的更多相关文章
- 1057 - Collecting Gold
1057 - Collecting Gold PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...
- hdu4336 Card Collector 状态压缩dp
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
- Marriage Ceremonies(状态压缩dp)
Marriage Ceremonies Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
随机推荐
- 浅析ASP.NET的状态保持
ASP.NET的状态保持:1.viewstate:隐藏域,记录服务器端控件的状态,适用于页面不关闭的情况下多次与服务器交互,页面自己给自己传值:文本框的改变事件.IspostBack也依赖viewst ...
- WPF动画之线性插值动画(1)
XAML代码: <Window x:Class="线性插值动画.MainWindow" xmlns="http://schemas.microsoft.com/wi ...
- mysql学习笔记2
drop database 数据库名称;————删除数据库 show columns from 数据表名[from 数据库名]:(或者 show columns from 数据库.数据表名:)———— ...
- IQueryable接口与IEnumberable区别
IEnumerable<T> 泛型类在调用自己的SKip 和 Take 等扩展方法之前数据就已经加载在本地内存里了,而IQueryable<T> 是将Skip ,take 这些 ...
- DataTable操作(建表,建行,建列,添加数据)
public DataTable GetNewTable() { DataTable dt2 = new DataTable("NewDataSet"); //创建一个新Table ...
- ilasm.exe与ildasm.exe的使用(编译与反编译)
ilasm.exe与ildasm.exe的使用(编译与反编译) 首先打开cmd命令.cd 到 C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0 ...
- python 自动化之路 day 02
本节内容: 列表.元组操作 字符串操作 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作 定义列表 1 names = ['Alex',&qu ...
- ubuntu thinkphp pathinfo 404等问题
这个问题 困扰了我一天,由于对nginx的配置文件中的各种变量不懂.配置起来很麻烦,从网上搜索的,感觉合适自己的不多!!! 找啊找啊..终于找一篇!!!! 我的环境: php ubuntu 12.04 ...
- jira汉化,破解,升级
交给我这个任务,我先在网络上查了,好些资料,先实验的是6.3.6版本的,这个安装包我是从csdn上下载的.tar.gz的安装,汉化过程也都没有问题.但是在运行过程中不显示下拉菜单,于是我又在官网下载的 ...
- c# winform textbox与combox让用户不能输入
textbox的ReadOnly属性设置为true combox的Enable属性设置为false 运行后效果如下 点击第一个和第二个,会把按钮text赋值给文本框和combox 并且用户不能输入