Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //using namespace chrono;
- typedef long long ll;
- typedef vector< int > vi;
- typedef vector < ll > V;
- typedef map<int, int > mp;
- #define pb push_back
- #define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
- #define F first
- #define S second
- #define debug cout << -1 << endl;
- #define REP(i, a, b) for(int i=a; i<b; i++)
- #define f0r(i, n) for (int i = 0; i < n; ++i)
- #define f0r1(i, n) for (int i = 1; i <= n; ++i)
- #define r0f(i, n) for(int i=n-1; i>=0; i--)
- #define fore(a, x) for (auto& a : x)
- #define fori(i, a, b) for (int i = (a); i < (b); ++i)
- #define MP make_pair
- #define UB upper_bound
- #define LB lower_bound
- #define nw cout << "\n"
- #define issq(x) (((ll)(sqrt((x))))*((ll)(sqrt((x))))==(x))
- #define rev(v) reverse(v.begin(),v.end())
- #define asche cerr<<"Ekhane asche\n";
- #define rev(v) reverse(v.begin(),v.end())
- #define srt(v) sort(v.begin(),v.end())
- #define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())
- #define all(v) v.begin(),v.end()
- #define mnv(v) *min_element(v.begin(),v.end())
- #define mxv(v) *max_element(v.begin(),v.end())
- #define valid(tx,ty) (tx>=0 && tx<n && ty>=0 && ty<m)
- #define one(x) __builtin_popcount(x)
- //#define pop pop_back
- #define setPrec(x) cout << fixed << setprecision(x)
- #define sz(a) (int)a.size()
- //#define fin cin
- //#define fout cout
- const int INF = 1e9;
- const ll INFL = 1e18;
- const double diff = 10e-6;
- const int maxn = 100005;
- const double PI = acos(-1);
- using namespace std;
- // int dx[] = {-1, 0, 1};
- // int dy[] = {-1, 0, 1};
- int n;
- ll arr[205][205];
- ll dp[205][205];
- bool ok(int i, int j)
- {
- if(arr[i][j]==-1) return false;
- return true;
- }
- ll dpF(int i, int j)
- {
- if(i>=2*n) return 0LL;
- if(dp[i][j]!=-1LL) return dp[i][j];
- ll op1 = 0LL, op2 = 0LL, op3 = 0LL;
- // option-1: just niche jao
- if(ok(i+1, j)) op1 = dpF(i+1, j);
- // option-2: niche left e jao
- if(ok(i+1, j-1) && i>=n) op2 = dpF(i+1, j-1);
- // option-3: niche right e jao
- if(ok(i+1, j+1) && i<n) op3 = dpF(i+1, j+1);
- return dp[i][j] = arr[i][j]+max({op1, op2, op3});
- }
- void solve()
- {
- memset(arr, -1LL, sizeof(arr));
- memset(dp, -1LL, sizeof(dp));
- cin >> n;
- for(int i=1; i<=n; i++) {
- for(int j=1; j<=i; j++) {
- cin >> arr[i][j];
- }
- }
- // int cnt = 0;
- for(int i=n+1; i<=2*n-1; i++) {
- // cnt++;
- for(int j=1; j<=n-(i-n); j++) cin >> arr[i][j];
- }
- cout << dpF(1, 1) << "\n";
- }
- int main()
- {
- FastIO;
- int t;
- t = 1;
- cin >> t;
- f0r(i, t) {
- cout << "Case " << i+1 << ": ";
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement