- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define scD(n) scanf("%lf", &n)
- #define scS(n) scanf("%s", &n)
- #define S 103
- using namespace std;
- int n, ar[S*3][S];
- int dp[S*3][S], sz[S*3];
- int MB(int row, int ind, int jump){
- if(row > (n+n-1) || ind < 0 || ind > sz[jump])return 0;
- if(dp[jump][ind] != -1)return dp[jump][ind];
- if(row < n)dp[jump][ind] = (ar[jump][ind] + max(MB(row+1, ind, jump+1), MB(row+1, ind+1, jump+1)));
- else dp[jump][ind] = (ar[jump][ind] + max(MB(row+1, ind-1, jump+1), MB(row+1, ind, jump+1)));
- return dp[jump][ind];
- }
- int main(){
- int t, cs = 0;
- scanf("%d", &t);
- while(t--){
- memset(dp, -1, sizeof(dp));
- memset(ar, 0, sizeof(ar));
- scanf("%d", &n);
- int z;
- for(int i = 0; i < n; i++){
- for(int j = 0; j <= i; j++){
- scanf("%d", &ar[i][j]);
- }
- sz[i] = i;
- z = i;
- }
- int jj = n-1;
- for(int i = z+1; i < (n+n-1); i++){
- for(int j = 0; j < jj; j++){
- scanf("%d", &ar[i][j]);
- }
- sz[i] = jj-1;
- jj--;
- }
- int ans = MB(1, 0, 0);
- cout << "Case " << ++cs << ": " << ans << endl;
- }
- return 0;
- }
Saturday, January 30, 2016
LightOJ - 1004 - Monkey Banana Problem
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment