/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* NAME : Nursoltan PROB : numtri LANG : C++ DATE : 01/07/11 14:08 */ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <sstream> #include <iostream> #include <map> #include <set> #include <stack> #include <utility> #include <queue> using namespace std; #define MAX 100 #define INF INT_MAX #define eps (1e-9) #define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++) #define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--) #define CLR(_x) memset((_x),0,sizeof(_x)) #define SQR(_x) ((_x)*(_x)) #define all(_x) _x.begin(),_x.end() #define sz(_x) sizeof(_x) #define vc vector<int> #define pb push_back #define mp make_pair #define iss istringstream #define oss ostringstream #define px first #define py second typedef long long ll; typedef pair <int,int> point; int ABS(int _x){ return _x>0?_x:-_x; } int main() { freopen("numtri.in","r",stdin); freopen("numtri.out","w",stdout); int n,a[1001][1001]; cin>>n; FOR(i,0,n) FOR(j,0,i+1) cin>>a[i][j]; FOR(i,1,n) a[i][0]+=a[i-1][0],a[i][i]+=a[i-1][i-1]; FOR(i,2,n) FOR(j,1,i) a[i][j]+=max(a[i-1][j],a[i-1][j-1]); cout<<(*max_element(a[n-1],a[n-1]+n))<<endl; //system("pause"); return 0; }