Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int a[100][100],dp[105][105],n;
- int recurse(int r,int c)
- {
- int temp=0;
- if(r==n)
- return 0;
- if(dp[r][c]!=-1)
- return dp[r][c];
- for(int j=0; j<n; j++)
- {
- if(c!=j)
- temp=max(a[r][j]+recurse(r+1,j),temp);
- }
- return dp[r][c]=temp;
- }
- int main()
- {
- int x;
- memset(dp,-1,sizeof dp);
- cin>>n;
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<n; j++)
- {
- cin>>a[i][j];
- }
- }
- int ans=recurse(0,n);
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement