Cod sursa(job #1970484)

Utilizator CiboAndreiAndrei Cibo CiboAndrei Data 19 aprilie 2017 13:20:18
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.24 kb
#include <fstream>

using namespace std;

int t[23][23];

int main()
{
ifstream f("robinson.in");
ofstream g("robinson.out");

int i,j,m,n,l,c;

f>>m>>n>>l>>c;

for(j=1;j<=m;j++)
{
    t[j][1]=n+j-1;
    t[1][j]=n+j-1;
}

for(i=2;i<=m;i++)
    for(j=2;j<=m;j++)
    {
    t[i][j]=t[i-1][j]+t[i][j-1];

    if(t[i][j]>999)
        t[i][j]-=1000;
    }

g<<t[m][m]<<'\n'<<l<<" "<<c<<'\n';

while(l<=m and c<=m and t[l][c]!=-1)
{
    if(t[l][c]%4==0)
    {
        if(l-1>0 and t[l][c]!=-1)
            {
                t[l][c]=-1;
                l--;
            }
        else
            break;
    }
    else if(t[l][c]%4==1)
    {
        if(c+1<=m and t[l][c]!=-1)
            {
            t[l][c]=-1;
            c++;
            }
        else
            break;
    }
    else if(t[l][c]%4==2)
    {
        if(l+1<=m and t[l][c]!=1)
            {
            t[l][c]=-1;
            l++;
            }
        else
            break;
    }
    else if(t[l][c]%4==3)
    {
        if(c-1>0 and t[l][c]!=1)
           {
            t[l][c]=-1;
            c--;
           }
        else
            break;
    }

    if(t[l][c]!=-1)
    g<<l<<" "<<c<<'\n';
}

    return 0;
}