Interview-Harry Potter walk through matrix.
假设你是harry potter,在grid的左上角,你现在要走到右下角,grid中有正数也有负数,遇到正数表示你的strength增加那么多,遇到负数表示strength减少那么多,在任何时刻如果你的strength小于等于0,那么你就挂了。在一开始你有一定的初始的strength,现在问这个初始的strength最少是多少,才能保证你能够找到一条路走到右下角。每一步只能向右或者向下。
http://www.mitbbs.com/article_t1/JobHunting/32611137_0_1.html
Analysis:
Assume d[i][j] means that after reaching grid[i][j], how much strength you should have at least to reach the goal. Then we have formula:
d[i][j] = min{d[i+1][j]-grid[i+1][j], d[i][j+1]-grid[i][j+1]} or 0 if the min value is less than 0.
The negtive value of min{d[i+1][j]-grid[i+1][j], d[i][j+1]-grid[i][j+1]} means that you actually need negtive strength to reach the goal starting at grid[i][j] because there is path whose accumulative strength is positive. However, you cannot have negtive strength at d[i][j], because d[i][j] also means that how much strength you should accumlate when you walk from (0,0) to (i,j) so that you can reach the goal through (i,j). From this sense, a negtive value is not permitted, since you need reach grid[i][j]. In other word, for any i,j, we always have d[i][j] >=0 .
Interview-Harry Potter walk through matrix.的更多相关文章
- Codeforces 1332 D. Walk on Matrix(构造矩阵)
怎么构造呢? \(首先我们不可能去构造一个2000*2000的矩阵,那太复杂了\) \(也许我们可以看看2*2的矩阵??\) \[\left[ \begin{matrix} x&y\\ z&a ...
- Lintcode: Matrix Zigzag Traversal
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ZigZag-or ...
- Matrix Zigzag Traversal(LintCode)
Matrix Zigzag Traversal Given a matrix of m x n elements (m rows, ncolumns), return all elements of ...
- 题解-比赛CF1332
题解-比赛CF1332 比赛CF1332 [A] [B] [C] [D] [E] [F] [G] [A]Exercising Walk Exercising Walk \(T\) 组测试数据,每次给定 ...
- Codeforces Round #630 (Div. 2)
题目链接:https://codeforces.com/contest/1332 A. Exercising Walk 可走的最远距离:左:x-x1,右:x2-x,下:y-y1,上:y2-y 如果可以 ...
- Pramp mock interview (4th practice): Matrix Spiral Print
March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...
- Codeforces 954C Matrix Walk (思维)
题目链接:Matrix Walk 题意:设有一个N×M的矩阵,矩阵每个格子都有从1-n×m的一个特定的数,具体数的排列如图所示.假设一个人每次只能在这个矩阵上的四个方向移动一格(上下左右),给出一条移 ...
- Educational Codeforces Round 40 C. Matrix Walk( 思维)
Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk time limit per test 1 second memor ...
- Matrix Walk CodeForces - 954C
题意: 就是给出一连串的数字 这些数字是从第一个数字依次走过的 emm..就是这样.. 然后让你判断这个矩阵是否存在 如果存在输出行和列的数量 其中行..开到最大就好了...主要是判断列 在输入 ...
随机推荐
- 【转】windows 如何查看端口占用情况?
开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在任务管理器中选&qu ...
- Sublime_Tip_01
//JerryWeb //20150601 //WebTool | Sublime ======= Sublime_Tip_01======= 接触了Sublime后,才真正开始爱上了coding # ...
- 深入浅出ExtJS 第五章 树形结构
5.1 TreePanel的基本使用 //树是一种非常典型的数据结构; 5.1.1 创建一棵树 //树控件有Ext.tree.TreePanel类定义,控件的名称为TreePanel;TreePane ...
- Part 13 Cast and Convert functions in SQL Server
Part 28 Cast and Convert functions in SQL Server
- 北大ACM(POJ1013-Counterfeit Dollar)
Question:http://poj.org/problem?id=1013 问题点:排除+验证. Memory: 244K Time: 16MS Language: C++ Result: Acc ...
- 利用kvc对UITabBar上的UITabBarButton的尝试修改.md
一.前言 一次比较懒的想法,不想自定义UITabBar,也不想用第三方框架,于是想尝试修改苹果私有类来达到部分效果 效果如下 点击tabBar 上的按钮,图片有变大再变小的动画 tabBar 上某个按 ...
- (转)每天一个linux命令(46):vmstat命令
vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动进行监控.他是对系统的整体情况进行统计,不足之处是无法对某个进程进行深 ...
- Codevs 1097 校门外的树
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题目描述 Description 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米 ...
- 采用Service实现本地推送通知
在android的应用层中,涉及到很多应用框架,例如:Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架,通知机制,ActionBar框架等等. ...
- functional javascript
(转载请注明出处!) 今早带我的master跟我分享了他最近看<functional javascript>一书的感悟,瞬间觉得写1w行代码都不如看本好书来的好啊! 于是在下午的写的项目中 ...