Facebook
From magda, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 255
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin ("sumtri.in");
  4. ofstream fout ("sumtri.out");
  5. int a[105][105], c[105][105], d[105][105],n,t[105][105];
  6. int main()
  7. {
  8.     int i,j;
  9.     fin>>n;
  10.     for(i=1;i<=n;i++)
  11.         for(j=1;j<=i;j++)
  12.         fin>>t[i][j];
  13.     for(j=1;j<=n;j++)
  14.         c[n][j]=t[n][j];
  15.     for(i=n-1;i>=1;i--)
  16.         for(j=1;j<=i;j++)
  17.         if(c[i+1][j]>c[i+1][j+1])
  18.     {
  19.         c[i][j]=t[i][j]+c[i+1][j];
  20.         d[i][j]=j;
  21.     }
  22.     else
  23.     {
  24.         c[i][j]=t[i][j]+c[i+1][j+1];
  25.         d[i][j]=j+1;
  26.     }
  27.     fout<<c[1][1]<<endl;
  28.     return 0;
  29. }