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..就是这样.. 然后让你判断这个矩阵是否存在 如果存在输出行和列的数量 其中行..开到最大就好了...主要是判断列 在输入 ...
随机推荐
- css子元素的margin-top为何会影响父元素
详细内容请点击 这个问题困惑了很久,虽然没有大碍早就摸出来怎么搞定它,但始终不明白原因出在哪里,如果只是IE有问题我也不会太在意,可问题是所有上等浏览器都表现如此,这样叫我怎能安心?今天总算下狠心查出 ...
- HDU4272LianLianKan(dfs)
Problem Description I like playing game with my friend, although sometimes looks pretty naive. Today ...
- 删除utorrent广告栏
自从utorrent附带广告栏后整个页面很难看,特别是右面下载详细列表变得支离破碎,今天实在是忍不了,网络搜索关键字“remove utorrent ads”,有效解决了问题. 具体如下:打开设置,选 ...
- php nginx fastdfs 下载文件重命名
其实fdfs可以传入一个filename参数,指定文件名.. M00/00/00/fwAAAVGMateAafjTAAAABBW-xbM368.txt?filename=test.txt 这样下载时用 ...
- ASP.Net 获取当前时间,包含各种时间格式
在c# / ASP.net中我们可以通过使用DataTime这个类来获取当前的时间.通过调用类中的各种方法我们可以获取不同的时间:如:日期(2008-09-04).时间(12:12:12).日期+时间 ...
- lamp环境的配置
转载请注明原作者出处 write by xiaoyang 一. 先决条件 系统:RHEL Server6.5 工具:MySQL.MySQL Server.PHP.PHP-MySQL.HTTPD等 ...
- UINavigationController与UITabbarController的样式
之前虽然也手写过这两中视图控制器,但是更多的还是使用SB来创建,最近发现了一些问题,现在总结一下. 1.改变UINavigationBar的颜色 在UINavigationController中,之前 ...
- Spring IoC容器的设计—2—主线
第二条接口设计主线是,以ApplicationContext应用上下文接口为核心的接口设计,这里涉及的主要接口设计有,从BeanFactory到ListableBeanFactory,再到Applic ...
- ZLComboBox自定义控件开发详解
[引言]距离上一回写博客已经有一些时日了,之前的爱莲iLinkIT系列主要是讲解了如何用NodeJS来实现一个简单的“文件传送”软件,属于JavaScript中在服务器端的应用. 今天,我们就回归到J ...
- pop()实现逐个删除数组最后一位并输出
使用pop()循环输出数组的最后一个元素 var a = []; a.push(1);a.push(3.1415926);a.push("number");a.push(" ...