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