所属分类:
中间件编程
开发工具:Pascal
文件大小:3KB
下载次数:1
上传日期:2008-06-01 10:11:05
说明: 动态规划的方程大家都知道,就是
f[i,j]=min{f[i-1,j-1],f[i-1,j],f[i,j-1],f[i,j+1]}+a[i,j]
但是很多人会怀疑这道题的后效性而放弃动规做法。
本来我还想做Dijkstra,后来变了没二十行pascal就告诉我数组越界了……(dist:array[1..1000*1001
div 2]...)
无奈之余看了xj_kidb1的题解,刚开始还觉得有问题,后来豁然开朗……
反复动规。上山容易下山难,我们可以从上往下走,最后输出f[n][1]。
xj_kidb1的一个技巧很重要,每次令f[i][0]=f[i][i],f[i][i+1]=f[i][1](xj_kidb1的题解还写错了)
(Dynamic programming equation we all know, that is, f [i, j] = min (f [i-1, j-1], f [i-1, j], f [i, j-1], f [i , j+ 1])+ a [i, j] However, many people would suspect that the aftereffect of这道题give up the practice of dynamic regulation. Originally, I also want to Dijkstra, later changed twenty lines did not tell me pascal on an array of cross-border ... ... (dist: array [1 .. 1000* 1001 div 2 ]...) watched helplessly while the title xj_kidb1 solution the beginning also think there is a problem, then suddenly see the light ... ... repeatedly dynamic regulation. Difficult to easily down the mountains, we can walk down from the final output f [n] [1]. xj_kidb1 a skill is important, every time the f [i] [0] = f [i] [i], f [i] [i+ 1] = f [i] [1] (xj_kidb1 solution of the title is also wrong a))