Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- freopen("in.txt","r",stdin);
- freopen("out.txt","w",stdout);
- int cas,n,monkey[200][200],dp[200][200],i,j,k,ans=0,row,col,t;
- cin>>t;
- for(cas=1;cas<=t;cas++)
- {
- cin>>n;
- for(i=0;i<n;i++)
- {
- row=i;
- for(j=0;j<=i;j++,row--){
- cin>>monkey[row][j];
- }
- }
- for(i=1;i<n;i++)
- {
- row=n-1;
- for(j=i;j<n;j++,row--)
- {
- cin>>monkey[row][j];
- }
- }
- /* for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- cout<<monkey[i][j]<<" ";
- cout<<endl;
- }
- */
- ans=monkey[0][0];
- dp[0][0]=monkey[0][0];
- for(i=1;i<n;i++)
- {
- ans+=monkey[0][i];
- dp[0][i]=ans;
- }
- ans=monkey[0][0];
- for(i=1;i<n;i++)
- {
- ans+=monkey[i][0];
- dp[i][0]=ans;
- }
- for(i=1;i<n;i++)
- {
- for(j=1;j<n;j++)
- {
- dp[i][j]=max((dp[i][j-1]+monkey[i][j]),(dp[i-1][j]+monkey[i][j]));
- }
- }
- /* for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- cout<<dp[i][j]<<" ";
- cout<<endl;
- }
- */
- cout<<"Case "<<cas<<": "<<dp[n-1][n-1]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement