ZOJ 3555 Ice Climber(dp)
晦涩的题意+各种傻逼害我调了那么久,实际上题目就是一个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)的更多相关文章
- ZOJ3555 Ice Climber(dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Ice Climber Time Limit: 2 Seconds Me ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- ZOJ Problem Set - 3822Domination(DP)
ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...
- HDU(3555),数位DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others ...
- HDU 3555 Bomb 数位dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...
- zoj 3537 Cake 区间DP (好题)
题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[ ...
- hdoj 3555 Bomb(DFA+dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 思路分析:该问题要求求解1—N中的数中含有49的数的个数,可以使用DFA来递推dp公式:详细解释 ...
- ZOJ 3623 Battle Ships DP
B - Battle Ships Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- zoj 2860 四边形优化dp
Breaking Strings Time Limit: 2 Seconds Memory Limit: 65536 KB A certain string-processing lan ...
随机推荐
- FineUI PK DWZ
一.概述 FineUI(ExtAspNet)是基于 jQuery / ExtJS 的 ASP.NET 控件库. DWZ是基于JQuery的一个客户端框架. 二.比较 三.总结 这两个东西实质都是对控件 ...
- Spring IOC 方式结合TESTGN测试用例,测试简单java的命令模式
java命令模式: 可以命令("请求")封装成一个对象,一个命令对象通过在特定的接收着上绑定一组动作来封装一个请求.命令对象直接把执行动作和接收者包进对象中,只对外暴露出执行方法的 ...
- MongoDB学习笔记-创建、更新、删除文档
创建 MongoDB中使用insert方法来向集合插入文档,然后保存到MongoDB中. db.foo.insert({"hehe":"呵呵"} ...
- WCF note1
Summary of WCF Client to use service use ChannelFactory to create proxy to use service. Client code ...
- 微信支付.NET版开发总结(JS API),好多坑,适当精简。
前2天,做一个手机网页的微信支付的项目,费了好些周折,记录一下.接下来,按照开发步骤,细数一下,我遇到的那些坑. [坑1]官方邮件中下载的demo只有PHP版本,其他版本没有给链接.可能让人误以为只有 ...
- vs2010运行C程序时,运行结果窗口一闪而过
摘要:vs2010运行C程序时,运行结果窗口一闪而过; ------------------------------------------------------------ Ctrl F5测试运行 ...
- Labview实现脉波调制( PPM )
Labview实现脉波调制( PPM ) 根据定义为脉冲宽度调制 生成一个正弦信号,得到其幅值输入给一个方波信号的偏移量 由于方波信号的偏移量里面含有正弦信号的信息 因此通过对方波信号的上升沿或下降沿 ...
- Ubuntu 关闭锁屏界面的 on-screen keyboard
试了试屏幕键盘,在 系统设置里开启了,又关了,但是在屏幕解锁时总是出现 screen keyboard,老烦人了,不知到在哪里关闭了,系统设置里面都关了,网上搜了解决办法,原来在这里 把 show w ...
- Java Day 12
包 编译格式 javac -d . **.java 包之间的访问 类找不到: 类名写错,包名.类名 包不存在:指定classpath 其他包的类无法访问:权限 public protected 包导入 ...
- preseed.cfg分区设定案例
很久之前做ubuntu的PXE配置ubuntu的preseed费了很大的力气,总结的不多,现在温习一下. 就我所接触的,有分区普通磁盘,LVM,和raid三种方式.其中前两中方式比较多,raid方式是 ...