Advertisement
juyana

basavara

May 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int a[100][100],dp[105][105],n;
  6. int recurse(int r,int c)
  7. {
  8. int temp=0;
  9. if(r==n)
  10. return 0;
  11. if(dp[r][c]!=-1)
  12. return dp[r][c];
  13.  
  14. for(int j=0; j<n; j++)
  15. {
  16. if(c!=j)
  17. temp=max(a[r][j]+recurse(r+1,j),temp);
  18. }
  19.  
  20.  
  21. return dp[r][c]=temp;
  22. }
  23.  
  24. int main()
  25. {
  26. int x;
  27. memset(dp,-1,sizeof dp);
  28. cin>>n;
  29. for(int i=0; i<n; i++)
  30. {
  31. for(int j=0; j<n; j++)
  32. {
  33. cin>>a[i][j];
  34. }
  35. }
  36. int ans=recurse(0,n);
  37. cout<<ans<<endl;
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement