1 #include <bits/stdc++.h> 2 #define _xx ios_base::sync_with_stdio(0);cin.tie(0); 3 using namespace std; 4 typedef long long ll; 5 ll dp[505][505] = {0}; 6 ll a[505][505] = {0}; 7 int main() 8 { 9 ll n; 10 cin >> n; 11 for(int i = 1; i <= n; i++) 12 for(int j = 1; j <= n; j++) cin >> a[i][j]; 13 for(int i = 0; i <= n; i++) dp[i][0] = dp[0][i] = 0; 14 for(int i = 1; i <= n; i++) 15 { 16 for(int j = 1; j <= n; j++) 17 { 18 dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i][j]; 19 } 20 } 21 cout << dp[n][n] << endl; 22 return 0; 23 }