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 ...
随机推荐
- gRPC 在 Python中的应用
python -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. hello.proto 简介 在python ...
- jOrgChart二叉树效果
引进文件: <link rel="stylesheet" type="text/css" href="Public/com/jQrgChart/ ...
- ORACLE 数据库管理
[故障处理]ORA-12162: TNS:net service name is incorrectly specified 本文将给大家阐述一个因未设置系统环境变量ORACLE_SID导致ORA-1 ...
- git反悔
Checkout checkout命令用于从历史提交(或者暂存区域)中拷贝文件到工作目录,也可用于切换分支.  ![ ...
- spring mvc 配置之 context:annotation-config vs component-scan
<context:annotation-config/> spring的注解@Resource.@Autowire, @Required and @Qualifier 等注解只是一个提示, ...
- Connector for Python
连接mysql, 需要mysql connector, conntector是一种驱动程序,python连接mysql的驱动程序,mysql官方给出的名称为connector/python, 可参考m ...
- 【winform】serialPort 串口
一. 1.串口通信简单实现 该来的总会来的,学做硬件的,串口这个东西必须得门清. 俗话说的好,不会做串口助手的电子工程师不是好程序员.
- vue.js使用vue-preview做移动端缩略图时报错Property or method "$preview" is not defined
报错的详细信息为: Property or method "$preview" is not defined on the instance but referenced duri ...
- vue学习笔记—bootstrap+vue用户管理
vue,读音view,简单易用的前端框架.特点如下: 1.一个mvvm的前端框架,内部做好了html中dom对象和后台用js语言定义的变量的双向绑定 2.中国人尤雨溪维护的个人项目,中文资料多,和go ...
- LeetCode 链表(旋转链表61)
/* * 给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数. * 构造一个环,对链表进行处理. * *实现原理:先遍历一遍,得出链表长度,注意K可能大于len,之后令k% ...