Advertisement
nontawat1996

9 tableowl #EOCI22

Feb 9th, 2013
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define x 5000005
  4. int n,m,map[505][505]={0};
  5. int sum[505][505]={0};
  6. int main()
  7. {
  8.     int i,j;
  9.     scanf("%d%d",&n,&m);
  10.     for(i=1;i<=n;i++)
  11.     {
  12.         for(j=1;j<=m;j++)
  13.         {
  14.             scanf("%d",&map[i][j]);
  15.             if(i==1)
  16.             {
  17.                 sum[i][j]=map[i][j];
  18.             }
  19.         }
  20.     }
  21.     for(i=2;i<=n;i++)
  22.     {
  23.         for(j=1;j<=m;j++)
  24.         {
  25.             if(sum[i-1][j-1]<=0) sum[i-1][j-1]=x;
  26.             if(sum[i-1][j+1]<=0) sum[i-1][j+1]=x;
  27.  
  28.             if(sum[i-1][j-1]<sum[i-1][j+1])
  29.             {
  30.                 sum[i][j]=sum[i-1][j-1]+map[i][j];
  31.             }
  32.             else sum[i][j]=sum[i-1][j+1]+map[i][j];
  33.         }
  34.     }
  35.     /*printf("---------\n");
  36.     for(i=1;i<=n;i++)
  37.     {
  38.         for(j=1;j<=m;j++)
  39.         {
  40.             printf("%d ",sum[i][j]);
  41.         }
  42.         printf("\n");
  43.     }*/
  44.     int min=sum[n][m];
  45.     for(j=1;j<=m;j++) if(sum[n][j]<min) min=sum[n][j];
  46.     printf("%d",min);
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement