Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int dp[105][105];
- int main()
- {
- int n;
- cin>>n;
- int matrica[n][n];
- for(int i=0; i<n; i++){
- for(int j=0; j<=i; j++){
- cin>>matrica[i][j];
- }
- }
- for(int i=0; i<n; i++){
- for(int j=0; j<n; j++){
- dp[i][j]=-2e9;
- }
- }
- dp[0][0] = 0;
- for(int i=0; i<n; i++){
- for(int j=0; j<=i; j++){
- dp[i+1][j]=max(dp[i+1][j], dp[i][j]+matrica[i][j]);
- if(j+1<=i + 1 ){
- dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j]+matrica[i][j]);
- }
- }
- }
- int result=0;
- for(int i=0; i<=n ; i++){
- for(int j=0; j<=i; j++){
- result=max(result, dp[i][j]);
- }
- }
- cout<<result;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement