Pagini recente » Borderou de evaluare (job #384736) | Borderou de evaluare (job #384734) | Cod sursa (job #363667) | Cod sursa (job #363665) | Cod sursa (job #368854)
Cod sursa(job #368854)
#include<iostream>
using namespace std;
int main()
{
int a[100][100],best[100][100],datas[100],m,n,i,j,maxi;
cin>>m;
cin>>n;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
cin>>a[i][j];
for(i=1;i<=n;i++)
best[n][i]=a[n][i];
for(i=n-1;i>=1;i--)
for(j=1;j<=n;j++)
{best[i][j]=1000;
if(a[i+1][j-1]<a[i+1][j])
if(a[i+1][j-1]<a[i+1][j+1])
if(j>1)
{best[i][j]=a[i][j]+best[i+1][j-1];
datas[i]=1;
}
else
if(j<n)
{ best[i][j]=a[i][j]+best[i+1][j+1];
datas[i]=3;
}
else
if(a[i+1][j]<a[i+1][j+1])
{best[i][j]=a[i][j]+best[i+1][j];
datas[i]=2;
}
else
if(j<n)
{ best[i][j]=a[i][j]+best[i+1][j+1];
datas[i]=3;
}
}
maxi=0;
best[1][maxi]=0;
for(i=1;i<=n;i++)
{if(best[1][i]<best[1][maxi])
maxi=1;
}
cout<<best[1][maxi];
return 0;
}