> Description
设有一个n×m(小于100)的方格(如图所示),在方格中去掉某些点,方格中的数字代表距离(为小于100的数,如果为0表示去掉的点),试找出一条从A(左上角)到B(右下角)的路径,经过的距离和为最小(此时称为最小代价),从A出发的方向只能向右,或者向下。
> Input
> Output
> Sample Input
4 4
4 10 7 0
3 2 2 9
0 7 0 4
11 6 12 1
> Sample Output
(1,1)->(2,1)->(2,2)->(2,3)->(2,4)->(3,4)->(4,4)
24
> 解题思路
这一道题用动态规划来做。
这一道题本来hin简单,只用判断上面和左边的数哪一个小就加上哪一个就行了,但是它偏偏要用一个0的障碍物,所以呢所以那就算了吧让我们共享时间……,就要在判断这里多很多判断。然后还要输出过程,我是用了一个bool来记录,false(0)是右边,true(1)是上面。
> 代码
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=105;
int n,m,a[maxn][maxn]={
0},f[maxn][maxn]={
0};
bool c[maxn][maxn];
int ooo(int s,int t)
{
if(