Optimal game strategy 1

My code is written right but it is not outputing anything

#include<bits/stdc++.h>

using namespace std;

#define watch(x) cout << (#x) << " is " << (x) << β€œ\n”

#define watch2(x,y) cout <<(#x)<<" is β€œ<<(x)<<” and β€œ<<(#y)<<” is β€œ<<(y)<<”\n"

#define watch3(x,y,z) cout <<(#x)<<" is β€œ<<(x)<<” and β€œ<<(#y)<<” is β€œ<<(y)<<” and β€œ<<(#z)<<” is β€œ<<(z)<<”\n"

#define ll long long

#define ff first

#define ss second

#define null NULL

#define allΒ© Β©.begin(),Β©.end()

#define nl β€œ\n”

#define ld long double

#define eb emplace_back

#define pb push_back

#define pf push_front

#define mod 1000000007

typedef vector vl;

typedef vector< vl > vvl;

typedef pair< ll,ll> pll;

typedef map< ll,ll> mll;

ll n;

vl a;

ll dp[50][50];

ll f(ll i,ll j){

if(j==i+1){

    return max(a[i],a[j]);

}

if(dp[i][j] != -1)

    return dp[i][j];

ll op1 = a[i] + min( f(i+2,j) , f(i+1,j-1) );

ll op2 = a[j] + min( f(i,j-2) , f(i+1,j-1) );

return dp[i][j] = max(op1,op2);

}

int main() {

// Use ctrl+shift+b ( second option )

ios_base::sync_with_stdio(false);

cin.tie(0);

cout.tie(0);

cin>>n;

a.clear();

for(ll i=0;i<n;i++){

    cin>>a[i];

}

for(ll i=0;i<50;i++){

    for(ll j=0;j<50;j++){

        dp[i][j] = -1;

    }

}

ll ans = f(0,n-1);

cout<<ans<<"\n";

return 0;

}

Hi, please paste the code at ide.codingblocks.com and share the link.

Thanks

After clearing the vector in line 75, the size of vector becomes 0. To take input as you are taking, you need to resize it first

a.resize(n)

okayy …