UVALive - 5857 Captain Q's Treasure
思路:
状压dp,用map写
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n"; const int N = ;
char s[N][N];
pii a[N];
int n, m, cnt, num[N];
LL p[N];
map<LL, int> dp[];
int main() {
p[] = ;
for (int i = ; i < N; ++i) p[i] = p[i-]*;
while(~scanf("%d %d", &n, &m)) {
if(!n && !m) break;
for (int i = ; i < n; ++i) scanf("%s", s[i]);
cnt = ;
for (int i = ; i < n; ++i) {
for (int j = ; j < m; ++j) {
if(isdigit(s[i][j])) {
a[cnt].fi = i;
a[cnt].se = j;
num[cnt] = s[i][j]-'';
++cnt;
}
}
}
dp[].clear(); dp[].clear();
int now = ;
dp[now][] = ;
int k;
for (int i = ; i < n; ++i) {
for (int j = ; j < m; ++j) {
now ^= ;
dp[now].clear();
for (auto t : dp[now^]) {
LL x = t.fi;
for (k = ; k < cnt; ++k) {
if((x/p[k])% != num[k] && (i*m+j)-(a[k].fi*m+a[k].se) >= m+) break;
}
if(k < cnt) continue;
if(dp[now].find(x) == dp[now].end()) dp[now][x] = t.se;
else dp[now][x] = min(dp[now][x], t.se);
if(s[i][j] == '.') continue;
for (k = ; k < cnt; ++k) {
if(i- <= a[k].fi && a[k].fi <= i+ && j- <= a[k].se && a[k].se <= j+) {
if((x/p[k])% == num[k]) break;
x += p[k];
}
}
if(k < cnt) continue;
if(dp[now].find(x) == dp[now].end()) dp[now][x] = t.se + ;
else dp[now][x] = min(dp[now][x], t.se + );
}
}
}
LL x = ;
for (int i = ; i < cnt; ++i) x += num[i]*p[i];
printf("%d\n", dp[now][x]);
}
return ;
}
UVALive - 5857 Captain Q's Treasure的更多相关文章
- Codeforces Round #660 (Div. 2) Captain Flint and Treasure 拓扑排序(按照出度、入读两边拓扑排序)
题目链接:Captain Flint and Treasure 题意: 一种操作为 选一个下标 使得ans+=a[i] 且 把a[b[i]]+a[i] 要求每个下标都进行一种这样的操作,问怎么样的 ...
- IGS_学习笔记03_Integrated SOA Gateway设定配置(案例)
20150506 Created By BaoXinjian
- BZOJ4152The Captain[DIjkstra]
4152: [AMPPZ2014]The Captain Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 700 Solved: 266[Submit ...
- 循环队列+堆优化dijkstra最短路 BZOJ 4152: [AMPPZ2014]The Captain
循环队列基础知识 1.循环队列需要几个参数来确定 循环队列需要2个参数,front和rear 2.循环队列各个参数的含义 (1)队列初始化时,front和rear值都为零: (2)当队列不为空时,fr ...
- 【暑假】[实用数据结构]UVAlive 3135 Argus
UVAlive 3135 Argus Argus Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- 二分+最短路 uvalive 3270 Simplified GSM Network(推荐)
// 二分+最短路 uvalive 3270 Simplified GSM Network(推荐) // 题意:已知B(1≤B≤50)个信号站和C(1≤C≤50)座城市的坐标,坐标的绝对值不大于100 ...
- 【暑假】[深入动态规划]UVAlive 3983 Robotruck
UVAlive 3983 Robotruck 题目: Robotruck Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format ...
- 【暑假】[实用数据结构]UVAlive 4670 Dominating Patterns
UVAlive 4670 Dominating Patterns 题目: Dominating Patterns Time Limit: 3000MS Memory Limit: Unkn ...
- hdu 5446 Unknown Treasure lucas和CRT
Unknown Treasure Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
随机推荐
- MySQL InnoDB Online DDL学习
MySQL Online DDL这个新特性是在MySQL5.6.7开始支持的,更早期版本的MySQL进行DDL对于DBA来说是非常痛苦的.现在主流版本都集中在5.6与5.7,为了更好的理解Online ...
- VS2017 异常 Editor or Editor Extension
KE遇到的第一个问题 VS 2017 打开文件的时候, 遇到异常 检查 activity_log发现是 Editor or Editor Extension, 解决办法: 安装插件, Clear ME ...
- VUE2 项目 引入 leaflet.draw全过程
leaflet.draw的参考文档:http://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html 这个网址不稳定,多刷新几 ...
- Unity 特写镜头
using UnityEngine; public class Camera_Feature : MonoBehaviour { public static Camera_Feature instan ...
- bochs模拟器创建映像文件 、写入文件并启动
安装 bochs,dd for windows,nasm,并将安装目录加入到环境变量中. 我用的bochs版本是2.6.8 1.用 bochs 中 bximage.exe 创建新的 img 文件 2. ...
- 在sql中case子句的两种形式
case子句,在select后面可以进行逻辑判断. 两种形式:判断相等.判断不等 一.判断相等的语法: case 列名 when ... then ... when ... then ... el ...
- jdk5升8问题记录-Spring2升4
Spring2.x升4.x Hibernate3.x升5.0 jdbcOperations.queryForInt 替换为 queryForObject(sql, parameters, Intege ...
- h5页面在ios机上禁止长按复制
(注意,增加之后需要对input的另外设置,不然输入框无法输入)场景:H5出现一个按钮需要长按几秒展示动画的,如:skcs.net-tactic.com/wap/peace/index,这时就需要用到 ...
- John Deere Service Advisor with Nexiq clone 90% Worked
FYI, John Deere Service Advisor 90% works with Nexiq China clone. Topic 1: John deere SA possible wi ...
- TortoiseGit拉取或推送,输入账号密码后提示 HTTP Basic: Access denied fatal: Authentication failed 解决方案
TortoiseGit拉取或推送项目,输入账号密码后,提示 HTTP Basic: Access denied fatal: Authentication failed. 大体意思是,HTTP基本认证 ...