晦涩的题意+各种傻逼害我调了那么久,实际上题目就是一个dp[i][j],dp[i][j]表示第i层第j个最少需要多少时间,当我们去更新dp[i][j]的时候,考虑的是从第i+1层的某一个dp[i+1][k]往上顶一层,然后走到dp[i][j]的位置,当然往上跳的时候要注意不要碰到怪物墙壁,各种坑,我的码力果然不行呀- -0

#pragma warning(disable:4996)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#define maxn 2500
#define maxw 220
using namespace std; int dp[maxn][maxw];
char num[maxn][maxw];
char type[maxn][maxw];
int n, w;
int t1, t2, t3; int main()
{
while (cin >> n >> w)
{
scanf("%d%d%d", &t1, &t2, &t3);
for (int i = 1; i <= n; i++){
scanf("%s", type[i] + 1);
scanf("%s", num[i] + 1);
}
memset(dp, 0x3f, sizeof(dp));
dp[n][1] = 0; int tmp = 0;
//if (type[n][1] == '|' || num[n][1] == '0'||type[n][1]=='#') dp[n][1] = 0x3f3f3f3f;
for (int i = 2; i <= w; i++){
if (dp[n][1] == 0x3f3f3f3f) break;
if (type[n][i] == '|' || num[n][i] == '0'){
break;
}
if (type[n][i] == '#') tmp += t3;
tmp += t1;
dp[n][i] = tmp;
}
for (int i = n - 1; i >= 1; i--){
for (int j = 1; j <= w; j++){
if (type[i][j] == '|'||num[i][j]=='0') continue;
int k = j - 1;
int cost = 0;
if (type[i][j] == '#') cost += t3;
bool flag = false;
while (k >= 1){
if (type[i][k] == '|') break;
if (num[i][k] == '0'){
flag = true;
}
if (type[i][k +1] != '#') dp[i][j] = min(dp[i][j], dp[i + 1][k] + cost + (num[i][k] - '0' + 1)*t2);
if (type[i][k] == '#') cost += t3;
cost += t1;
k--;
if (flag) break;
}
k = j + 1;
cost = 0;
flag = false;
if (type[i][j] == '#') cost += t3;
while (k <= w){
if (type[i][k] == '|') break;
if (num[i][k] == '0'){
flag = true;
}
if (type[i][k - 1] != '#') dp[i][j] = min(dp[i][j], dp[i + 1][k] + cost + (num[i][k] - '0' + 1)*t2);
if (type[i][k] == '#') cost += t3;
cost += t1;
k++;
if (flag) break;
}
}
}
int ans = 0x3f3f3f3f;
for (int i = 1; i <= w; i++){
ans = min(dp[1][i], ans);
}
if (ans == 0x3f3f3f3f) puts("-1");
else cout << ans << endl;
}
return 0;
}

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

  1. ZOJ3555 Ice Climber(dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Ice Climber Time Limit: 2 Seconds      Me ...

  2. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

  3. ZOJ Problem Set - 3822Domination(DP)

    ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...

  4. HDU(3555),数位DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others ...

  5. HDU 3555 Bomb 数位dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...

  6. zoj 3537 Cake 区间DP (好题)

    题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[ ...

  7. hdoj 3555 Bomb(DFA+dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 思路分析:该问题要求求解1—N中的数中含有49的数的个数,可以使用DFA来递推dp公式:详细解释 ...

  8. ZOJ 3623 Battle Ships DP

    B - Battle Ships Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  9. zoj 2860 四边形优化dp

    Breaking Strings Time Limit: 2 Seconds        Memory Limit: 65536 KB A certain string-processing lan ...

随机推荐

  1. [转]C++编写Config类读取配置文件

    //Config.h #pragma once #include <string> #include <map> #include <iostream> #incl ...

  2. 通过shell脚本获取日期,并赋给变量

    通过shell获取当前8位日期,并赋给变量,并且使用变量作为文件名,建立文件夹 代码如下: ls_date=`date +%Y%m%d` mkdir ${ls_date} 上面两句代码虽然简单 但是在 ...

  3. 从零开始学ios开发(四):IOS控件(1),Image View、Text Field、Keyboard

    长话短说,谢谢大家的关注,这篇写了好长时间,下面继续学习ios.我将用2到3篇的篇幅来学习iphone上的一些常用控件,包括Image View.Text Field.Keyboard.Slider等 ...

  4. 调整maven配置文件

    maven的配置文件位置:maven安装位置\conf\settings.xml. 这次调整maven的配置文件主要解决三个问题: 调整本地依赖库位置 设置代理 添加远程资源库镜像节点 调整本地依赖库 ...

  5. 20.时钟抖动(jitter)和时钟偏移(skew)的概念?

    jitter:由于晶振本身稳定性,电源以及温度变化等原因造成了时钟频率的变化,就是jitter,指的是时钟周期的变化.指两个时钟周期之间存在的差值,这个误差是在时钟发生器内部产生的,和晶振或者PLL内 ...

  6. webpack对样式的处理

    原文地址:https://github.com/zhengweikeng/blog/issues/9 我们可以在js中引入样式文件 require('myStyle.css') 这时我们便需要引入相应 ...

  7. 容器适配器之priority_queue

    template <class T, class Container = vector<T>,                class Compare = less<type ...

  8. IT安全的本质

    (1)信任:服务端信任客户端的请求参数. (2)可控:客户端的请求参数可以被控制,任意修改. 服务端信任+客户端可控 =不安全. 服务端信任+客户端不可控=安全. 服务端不信任+客户端可控=安全. 服 ...

  9. MySQL数据库远程连接开启方法

    有时候需要远程连接mysql数据库,默认是不可以的,可以参考下面的方法,解决下. 1.登陆自己机器的MySQL数据库:mysql -uroot -p密码 设置root用户可以任意IP访问,代码如下(可 ...

  10. 学习ThinkPHP-1

    ThinkPHP 自建路由 关于文件关联 当在Applicatin\Home\Controller文件夹下建立一个控制器时如LoginController.class.php 在此文件夹下还有一个默认 ...