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 ...
随机推荐
- 将pucharm与anaconda配合使用
一个用来更新各种包,另一个负责美美的打代码,把pycharm, setting project interpreter,选中anaconda中的python.exe.搞定.anaconda prom ...
- adobe air for ios 应用完成appstore评论
1,跳转到App Store:NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%d ...
- ZIP压缩指定路径
using Common; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Quartz; using Quartz.Impl; us ...
- upCode
更新源码 Sub main() Dim str As String str = "这是测试的字符串对话框" MsgBox str Sheets(1).Select End Sub
- newcode网学习笔记(1)
1.类的内存结构一开始指向的是虚函数表,指向虚函数表的指针为4个字节(32位系统)[类的内存结构最前面的是指向虚函数表的指针] 2.包含标准库文件以及相关命名空间,则系统不允许用户重新定义标准库函数, ...
- SV-assertion
断言(assert)是一种描述性语言,通过描述的期望结果来进行仿真验证. 断言有一个更加基础的信息,我们称为属性(property),属性可以作为断言结果,功能覆盖点,形式检查和约束随机激励生成. 断 ...
- FileOutputSream文件字节输出流
1.FileOutputSream文件字节输出流: 输入--写出--使用: 输出--写入--存储: 写出写入是对硬盘而言: 其中,OutputStream为所有类型的字节输出流的超类: FileO ...
- 20175208 实验二 《Java面向对象程序设计》实验报告
一.实验报告封面 课程:Java程序设计 班级:1752班 姓名:张家华 学号:20175208 指导教师:娄嘉鹏 实验日期:2019年4月09日~2019年4月18日 实验序号:实验二 实验 ...
- Recycle----项目总结
github项目地址:https://github.com/HuChengLing/recycle 软件规模: 我们这个Recycle app属于一个小型项目,整体规模不大.预期有垃圾回收和二手品交易 ...
- android上instant app介绍 类似于微信小程序
android上instant app介绍 类似于微信小程序instant app 是谷歌推出的类似于微信小程序(或者说小程序类似于instant app)的一项技术,用户无须安装应用,用完就走,同时 ...