mafia's blog

By mafia, 12 years ago, In English

Could someone help me with this task. I have a solution but it is saying Runtime error. Could someone say why? Here is my code:

#include<stdio.h>
#include<algorithm>
using namespace std;
int d[2002][102][102];
int a[102][102],n,m;
main()
{
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    int i,j,k,l,v;
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
        for (j=1;j<=n;j++)
            scanf("%d",&a[i][j]);
    d[0][0][1]=1;
    for (l=1;l<=m;l++)
        {
        for (i=1;i<=n;i++)
            {
            for (j=1;j<=n;j++)
                {
                v=max(max(d[l-1][i-1][j],d[l-1][i+1][j]),max(d[l-1][i][j-1],d[l-1][i][j+1]));
                if(v!=0)d[l][i][j]=v+a[i][j];
                if(i==j&&l==1&&i==1)d[l][i][j]--;
                if(l==m)
                    {
                    if(i==j&&i==1)
                        k=d[l][i][j];
                    k=max(k,d[l][i][j]);
                    }
                }
            }
        }
    printf("%d\n",k);
    return 0;
}
  • Vote: I like it
  • 0
  • Vote: I do not like it