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..就是这样.. 然后让你判断这个矩阵是否存在 如果存在输出行和列的数量 其中行..开到最大就好了...主要是判断列 在输入 ...
随机推荐
- DOM 1
首先getAttribute setAttribute只能被元素节点对象调用.(属性节点和文本节点调用不了) 我们可以通过一下三种方式得到元素: document.getElementById(); ...
- OGNL 对象视图导航语言
[Object Graphics Navigate Language] 类似于EL(Expression Language)表达式, 可以帮助我们在配置文件.JSP中来获取对象的值 这门语言比EL功能 ...
- javascript面向对象的理解(一)
第一次在园子发文: 关于js面向对象的理解: 工厂方式是什么?构造函数是什么?原形链?对象的引用? 1.对象是什么? 在js接触的比较多的就是对象了,比如: var arr = []; arr.num ...
- Part 48 to 51 Talking about Access Modifiers in C#
Part 48 Difference between Types and Type Members Part 49 Access Modifiers in C# Part 50 Internal an ...
- CSS之侧边栏
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Swiper之滑块4
最炫3D走一波: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" ...
- WPF button 如何区分click和doubleclick
WPF button 同时处理两个事件时候会先触发click事件,触发doubleclick事件 ,那如何区分呢,可以这样设置: private static DispatcherTimer myC ...
- postfix部署多个Content Filter的方法
Postfix邮件服务器可以在接收邮件时使用content_filter来扫描邮件(病毒,广告等).通过整合一个集中化的电子邮件内容过滤器,比如amavis或mailscanner,Postfix可以 ...
- STL Container和ATL智能包裹类的冲突
STL Container和ATL智能包裹类的冲突 载自:http://www.codesky.net/article/200504/63245.html Article last modified ...
- BeanDefinition的Resource定位——2
1.FileSystemXmlApplicationContext的实现 public class FileSystemXmlApplicationContext extends AbstractXm ...