转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

Ice Climber


Time Limit: 2 Seconds      Memory Limit: 32768 KB

Maybe many one have played or at least heard of The Family Computer(FC). And this problem is mainly about a classical game named "Ice Climber"

In this game, our little Eskimo wants to climb higher and catch the big bird at last. In the climbing, little Eskimo may be faced with many troubles, like enemy or wall.

The game field made up with several floors and floors are seperated by many pieces of bricks. The number of pieces between different floors and different positions are different. There may also be enimies and walls on these bricks. By jumping up Eskimo can decrease the number of pieces on the ceiling of his position or even jump to another floor.

Each time Eskimo can choose on of the following steps:

  • Move left or right one block as long as the block is empty and the block has supporting pieces of bricks, using t1 time.(That is, there will not be an enemy or a wall on the block and the block has at least one bricks)
  • Jump up and destroy one piece of brick of the ceil just above little Eskimo or Jump up to an upper floor if all bricks on the ceiling of his current position have been cleared. If he jumps to the next floor he can choose to land on either the left or the right adjacent position as long as there are no enimies or walls on them (Of course there must also be at least a supporting brick at that position). Both kind of jumping takes t2 time.
  • Knock off one little enemy just next to little Eskimo in t3 time, and the enemy will disappear.

Each block has several pieces. And only if the number of the pieces of the block is 0 can little Eskimo jump up through it to the next floor. Sometimes Eskimo may clear all the bricks of ceiling of a position where there is an enemy standing on it, in these cases this unlucky enemy will be cleared at once. If on the next floor, above one block there is a wall, then Eskimo can never jump up through this block no matter how much pieces it has even zero. If little Eskimo jumped up to the next floor successfully, for instance through the ith position, he can choose to land on either to the left, the i-1th block or to the right, the i+1th block as you like, but not the ith block itself. And you can never jump over the enemy or the wall or the zero pieces blocks.

And in the whole process, little Eskimo can not land on to the side, that is, he can not land on to the 0th block or the w+1th block. Also, he cannot land on to where there are only zero pieces blocks or blocks with an enemy or blocks with a wall. And while moving, he cannot get to the 1st block from the nth block, or get to the nth block from the 1st block.

And just like the picture below, the 2nd floor's floor is the 1st floor's ceil:

Now, we have n floors, and each floor has the same width of w blocks, but the number of the pieces of each block can be different. Thus, we can get a map of these floors. Little Eskimo starts from the leftest block on the first floor, unlike the picture above, and we want to use the minimum time to get to the nth floor.(Any block on the nth is all right)

Input

The input contains multiple cases.

In each case, the first line contains two integers represents n and w.(1<=n<=2000 , 1<=w<=100)

The second line contains three integers represents t1t2, andt3.(0<=t1,t2,t3<=100)

Then the 2n lines, the odd lines contains w characters, describing what is on the floor: '#' represents the enemy, which we assume does not move, '|' represents wall, and '0' represents the block is empty. While the even lines contains w digits from '0' to '9' representing the number of the pieces of each block.

[Notice]: the map inputs from the nth floor downto the 1st floor, that is, the first line of this map describes what is on the nth floor, and the second line of this map describes the number of the pieces of each block of nth floor, or the n-1th floor's ceil.

Output

In each case, output one line with an integer representing the minimum time little Eskimo can get to the nth floor. If there is no way to get to the nth floor, output -1.

Sample Input

This sample input just describe the picture above.

5 22
1 2 3
0000000000000000000000
2222212222122222221222
0000000000000000000000
2122222122222221112222
000000000000000000000#
2222212221222222222111
0000000000000000000000
2222222222112222222221
0000#00000000000000000
1111111111111111111111

Sample Output

23

题目很长,大致规则和游戏中差不多,从最下面一层的左边出发,不能越过墙‘|’,打掉一个怪的时间是t3,水平走一步的时间是t1,往左上或者右上跳,并且打掉上方一个砖块的时间是t2,不能碰到怪,不能踩在空中,另外还有一些细节,然后要求到达最上面一层最少需要多少时间

dp[i][j] 表示走到第i层最少花费时间,这个点可以从下面一层任意一个可达的地方转移过来,所以复杂度就是n*w*w

 /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author xyiyy @https://github.com/xyiyy
*/ #include <iostream>
#include <fstream> //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype> using namespace std;
#define INF 0x3FFFFFFF
#define rep(X, N) for(int X=0;X<N;X++)
#define rep2(X, L, R) for(int X=L;X<=R;X++)
#define dep(X, R, L) for(int X=R;X>=L;X--) char f[][], s[][];
int dp[][]; class TaskG {
public:
void solve(std::istream &in, std::ostream &out) {
int n, w;
while (in >> n >> w) {
int t1, t2, t3;
in >> t1 >> t2 >> t3;
rep2(i, , n) {
in >> f[i] + ;
in >> s[i] + ;
}
rep(i, n + ) {
rep(j, w + )dp[i][j] = INF;
}
dp[n][] = ;
int num = ;
if (f[n][] == '|' || s[n][] == '')dp[n][] = INF;
rep2(i, , w) {
if (f[n][i] == '|' || s[n][i] == '')break;
if (f[n][i] == '#')num += t3;
num += t1;
dp[n][i] = dp[n][] + num;
}
dep(i, n - , ) {
rep2(j, , w) {
if (f[i][j] == '|' || s[i][j] == '')continue;
num = ;
if (f[i][j] == '#')num += t3;
bool ok = ;
dep(k, j - , ) {
if (f[i][k] == '|')break;
if (s[i][k] == '')ok = ;
if (f[i][k + ] != '#') dp[i][j] = min(dp[i][j], dp[i + ][k] + num + (s[i][k] - '' + ) * t2);
if (f[i][k] == '#')num += t3;
num += t1;
if (ok)break;
}
ok = ;
num = ;
if (f[i][j] == '#')num += t3;
rep2(k, j + , w) {
if (f[i][k] == '|')break;
if (s[i][k] == '')ok = ;
if (f[i][k - ] != '#')dp[i][j] = min(dp[i][j], dp[i + ][k] + num + (s[i][k] - '' + ) * t2);
if (f[i][k] == '#')num += t3;
num += t1;
if (ok)break;
}
}
}
int ans = INF;
rep2(i, , w)ans = min(ans, dp[][i]);
if (ans == INF)ans = -;
out << ans << endl;
}
}
}; int main() {
std::ios::sync_with_stdio(false);
std::cin.tie();
TaskG solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return ;
}

ZOJ3555 Ice Climber(dp)的更多相关文章

  1. ZOJ 3555 Ice Climber(dp)

    晦涩的题意+各种傻逼害我调了那么久,实际上题目就是一个dp[i][j],dp[i][j]表示第i层第j个最少需要多少时间,当我们去更新dp[i][j]的时候,考虑的是从第i+1层的某一个dp[i+1] ...

  2. FC红白机游戏列表(维基百科)

    1055个fc游戏列表 日文名 中文译名 英文版名 发行日期 发行商 ドンキーコング 大金刚 Donkey Kong 1983年7月15日 任天堂 ドンキーコングJR. 大金刚Jr. Donkey K ...

  3. HDU 1028 Ignatius and the Princess III (递归,dp)

    以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802  Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...

  4. Codeforces Gym 100418J Lucky tickets 数位DP

    Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  5. BZOJ_1021_[SHOI2008]_Debt循环的债务_(DP)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1021 三个人相互欠钱,给出他们每个人各种面额的钞票各有多少张,求最少需要传递多少张钞票才能把账 ...

  6. 最短路(数据处理):HDU 5817 Ice Walls

    Have you ever played DOTA? If so, you may know the hero, Invoker. As one of the few intelligence car ...

  7. Codeforces Round #301 (Div. 2)A B C D 水 模拟 bfs 概率dp

    A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. 4800: [Ceoi2015]Ice Hockey World Championship(折半搜索)

    4800: [Ceoi2015]Ice Hockey World Championship Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 622  S ...

  9. 2019CCPC秦皇岛I题 Invoker(DP)

    Invoker Time Limit: 15000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

随机推荐

  1. CSS中常用中文字体转Unicode编码表

    中文名 英文名 Unicode Unicode 2 Mac OS 华文细黑 STHeiti Light [STXihei] \534E\6587\7EC6\9ED1 华文细黑 华文黑体 STHeiti ...

  2. web前端知识

    4.表格与表单 4.1 动态添加行 <script language=”javascript”> window.onload=function(){ var oTr = document. ...

  3. Symfony2目录结构说明

    了解框架的目录结构是框架快速入门的一个途径,一个成熟的框架,每个功能模块都被划分存放在不同的目录. Symfony2一级目录结构: ├── app //这目录下包含了,配置文件(应用的配置文件会被im ...

  4. MBProgressHUD的基本使用

    MBProgressHUD的基本使用 分类: IOS2012-10-30 11:19 12047人阅读 评论(2) 收藏 举报 和gitHub上的Demo其实差不多,就是小整理了下,当备忘,想做复杂的 ...

  5. spark1.1.0源码阅读-executor

    1. executor上执行launchTask def launchTask( context: ExecutorBackend, taskId: Long, taskName: String, s ...

  6. Smarty 插件开发

    插件包含了: functions modifiers block functions compiler functions prefilters postfilters outputfilters r ...

  7. COJ 0248 HDNOIP201408生成树

    HDNOIP201408生成树 难度级别: A: 编程语言:不限:运行时间限制:5000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 输入 第一行包括两个整数V, ...

  8. Linux系统编程(33)—— socket编程之TCP程序的错误处理

    上一篇的例子不仅功能简单,而且简单到几乎没有什么错误处理,我们知道,系统调用不能保证每次都成功,必须进行出错处理,这样一方面可以保证程序逻辑正常,另一方面可以迅速得到故障信息. 为使错误处理的代码不影 ...

  9. Linux系统编程(26)——守护进程

    Linux系统启动时会启动很多系统服务进程,比如inetd,这些系统服务进程没有控制终端,不能直接和用户交互.其它进程都是在用户登录或运行程序时创建,在运行结束或用户注销时终止,但系统服务进程不受用户 ...

  10. 数组、List和ArrayList的区别

    有些知识点可能平时一直在使用,不过实际开发中我们可能只是知其然不知其所以然,所以经常的总结会对我们的提高和进步有很大的帮助,这里记录自己在工作之余的问题,持续更新,欢迎高手斧正. 数组.List和Ar ...