#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int a[10][10],n,b[10][10],c[10][10];
void citire()
{int i,j;
ifstream f("date");
f>>n;
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
f>>a[i][j];
}
void afisare()
{int i,j;
for(i=1;i<=n;i++)
{ for(j=1;j<=n;j++)
if(b[i][j]!=0)
cout<<setw(3)<<b[i][j];
cout<<endl;}
cout<<endl;
}
int maxim(int a,int b)
{if(a>b)
return a;
else return b;
}
int max2(int a[])
{int i,maxim=a[1];
for(i=1;i<=n;i++)
if(a[i]>maxim)
maxim=a[i];
return maxim;
}
int main()
{int i,j,p;
citire();
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
b[i][j]=maxim(b[i-1][j-1],b[i-1][j])+a[i][j];
afisare();
cout<<endl;
for(i=n;i>0;i--)
{p=max2(b[i]);
for(j=1;j<=i;j++)
{if(b[i][j]==p)
c[i][j]=1;}
}
cout<<"Drumul parcurs"<<endl;
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
if(c[i][j]==1)
cout<<a[i][j]<<" ";
}
Orar semigroup #2
2/12 - Matrice Triunghiulara
joi, 1 decembrie 2011
by DlMuresan
Categories:
Programare Dinamica
|
Leave a comment