- 晴天小猪历险记之Hill
- 2016-03-27 18:45:21 @
#include <iostream>
#include <stdio.h>
using namespace std;
int map[1010][1010];
int time[1010][1010];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
scanf("%d",&map[i][j]);
time[1][1]=map[1][1];
for(int i=2;i<=n;i++)
{
for(int j=2;j<i;j++)
time[i][j]=min(time[i-1][j],time[i-1][j-1])+map[i][j];
time[i][1]=min(time[i-1][1],time[i-1][i-1])+map[i][1];
time[i][i]=min(time[i-1][i-1],time[i-1][1])+map[i][i];
for(int k=i-1;k>0;k--)
time[i][k]=min(time[i][k],time[i][k+1]+map[i][k]);
time[i][i]=min(time[i][i],time[i][1]+map[i][i]);
for(int l=2;l<=i;l++)
time[i][l]=min(time[i][l],time[i][l-1]+map[i][l]);
time[i][1]=min(time[i][1],time[i][i]+map[i][1]);
for(int k=i-1;k>0;k--)
time[i][k]=min(time[i][k],time[i][k+1]+map[i][k]);
time[i][i]=min(time[i][i],time[i][1]+map[i][i]);
for(int l=2;l<=i;l++)
time[i][l]=min(time[i][l],time[i][l-1]+map[i][l]);
time[i][1]=min(time[i][1],time[i][i]+map[i][1]);
}
printf("%d",time[n][1]);
}
6 条评论
-
尹执信 LV 4 @ 2016-12-03 15:53:02
// input code here
-
2016-08-21 22:44:08@
两次dp是对的
-
2016-03-29 18:16:37@
怎么啦?你不是AC了么?
-
2016-03-27 18:45:54@
顶
-
2016-03-27 18:45:48@
顶顶
-
2016-03-27 18:45:38@
顶
- 1