Advertisement
erfanul007

LOJ 1004

Jul 27th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scii(n,m) scanf("%d %d",&n,&m)
  17. #define scl(n) scanf("%lld",&n)
  18. #define scd(n) scanf("%lf",&n)
  19. #define scs(s) scanf("%s",s)
  20. #define pfi(n) printf("%d",n)
  21. #define pfl(n) printf("%lld",n)
  22. #define pff(n) cout<<n
  23. #define line printf("\n")
  24. #define spc printf(" ")
  25. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  26. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  27. #define cspf(i) printf("Case %d: ", i)
  28. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  29. #define pb push_back
  30. #define mp make_pair
  31. #define ff first
  32. #define ss second
  33. #define all(v) v.begin(),v.end()
  34. #define rall(v) v.rbegin(),v.rend()
  35. #define read() freopen("input.txt", "r", stdin)
  36. #define write() freopen("output.txt", "w", stdout)
  37. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  38. /// Constants
  39. #define eps 1e-9
  40. #define PI acos(-1.0) // 3.1415926535897932
  41. #define MAX 1000009
  42.  
  43. int a[202][102],cnt[202][102];
  44.  
  45. int dpsolve(int i,int j,int n)
  46. {
  47. if(cnt[i][j]!=-1) return cnt[i][j];
  48. if(a[i][j]==-1) return a[i][j];
  49. if(i==(n*2)-1) return a[i][j];
  50. if(i<n) return cnt[i][j] = a[i][j] + max(dpsolve(i+1,j,n),dpsolve(i+1,j+1,n));
  51. else return cnt[i][j] = a[i][j] + max(dpsolve(i+1,j-1,n),dpsolve(i+1,j,n));
  52. }
  53.  
  54. int main()
  55. {
  56. //read();
  57. //write();
  58. int t;
  59. sci(t);
  60. loop(i,1,t){
  61. int n;
  62. sci(n);
  63. int x=1;
  64. memset(cnt,-1,sizeof(cnt));
  65. memset(a,-1,sizeof(a));
  66. loop(j,1,(n*2)-1){
  67. loop(k,1,x){
  68. sci(a[j][k]);
  69. }
  70. if(j<n) x++;
  71. else x--;
  72. }
  73. int mx = dpsolve(1,1,n);
  74. cspf(i);pfi(mx);line;
  75. }
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement