Advertisement
Farjana_akter

Untitled

Jul 28th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9. freopen("in.txt","r",stdin);
  10. freopen("out.txt","w",stdout);
  11. int cas,n,monkey[200][200],dp[200][200],i,j,k,ans=0,row,col,t;
  12. cin>>t;
  13. for(cas=1;cas<=t;cas++)
  14. {
  15. cin>>n;
  16. for(i=0;i<n;i++)
  17. {
  18. row=i;
  19. for(j=0;j<=i;j++,row--){
  20. cin>>monkey[row][j];
  21. }
  22. }
  23. for(i=1;i<n;i++)
  24. {
  25. row=n-1;
  26. for(j=i;j<n;j++,row--)
  27. {
  28. cin>>monkey[row][j];
  29. }
  30. }
  31. /* for(i=0;i<n;i++)
  32. {
  33. for(j=0;j<n;j++)
  34. cout<<monkey[i][j]<<" ";
  35. cout<<endl;
  36. }
  37. */
  38. ans=monkey[0][0];
  39. dp[0][0]=monkey[0][0];
  40. for(i=1;i<n;i++)
  41. {
  42. ans+=monkey[0][i];
  43. dp[0][i]=ans;
  44. }
  45. ans=monkey[0][0];
  46. for(i=1;i<n;i++)
  47. {
  48. ans+=monkey[i][0];
  49. dp[i][0]=ans;
  50. }
  51. for(i=1;i<n;i++)
  52. {
  53. for(j=1;j<n;j++)
  54. {
  55. dp[i][j]=max((dp[i][j-1]+monkey[i][j]),(dp[i-1][j]+monkey[i][j]));
  56. }
  57. }
  58. /* for(i=0;i<n;i++)
  59. {
  60. for(j=0;j<n;j++)
  61. cout<<dp[i][j]<<" ";
  62. cout<<endl;
  63. }
  64. */
  65. cout<<"Case "<<cas<<": "<<dp[n-1][n-1]<<endl;
  66. }
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement