Domaci Dimitrije Pesic

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <iostream>

using namespace std;


int mat[10][10];
int resenje[10][10];
void ispisi(int x, int y)
{
if(not(x==0&&y==0))
{
if(resenje[x-1][y]>=resenje[x][y-1])
{
ispisi(x-1,y);
cout<<"dole"<<endl;
}
else
{
ispisi(x,y-1);
cout<<"desno"<<endl;
}
}
}
int main()
{
int n;
cin>>n;
for(int i = 0; i<n; i++)
for(int j = 0; j<n; j++)
{
cin>>mat[i][j];
}
for(int i = 0; i<n; i++)
for(int j = 0; j<n; j++)
{
if(i==0)
resenje[i][j]=mat[i][j]+resenje[i][j-1];
else if(j==0)
resenje[i][j]=mat[i][j]+resenje[i-1][j];
else
resenje[i][j]=max(mat[i][j]+resenje[i][j-1], mat[i][j]+resenje[i-1]
[j]);
}
cout<<endl;
for(int i = 0; i<n; i++)
{
for(int j = 0; j<n; j++)
{
cout<<resenje[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<"Zbir: "<<resenje[n-1][n-1]<<endl;
ispisi(n-1,n-1);
return 0;
}

You might also like