ZCO12004 - Round Table

c-plus-plus
doubt
dynamic-programming
zco
zco12004
zcoprac

#1

My code fails some test cases. Could someone please point out the flaw or provide test cases which fail…

My approach uses memorization…


int minCost(int cost[] , int N , int i , bool first , int memo[][2])

{

bool prev = first;

if(i == N-1)
{
    if(prev == false)
        return cost*;

    if(first == true)
        return 0;

    if(first == false)
        return cost*;
}

if(prev)
{
    if(memo*[0])
        return memo*[0];

    else
        memo*[0] = min ( cost* + minCost(cost,N,i+1,prev,memo) ,
                           minCost(cost,N,i+1,!prev,memo));

    return memo*[0];
}

else
{
    if(memo*[1])
        return memo*[1];

    else
        memo*[1] = cost* + minCost(cost,N,i+1,!prev,memo);

    return memo*[1];
}

}

int main()

{

int N;
cin>>N;

int cost[N];

for(int i=0 ; i<N ; i++)
    cin>>cost*;

int memo[N][2];

for(int i=0 ; i<N ; i++)
    memo*[0] = memo*[1] = 0;

cout<<min( minCost(cost,N,0,false,memo) ,
           minCost(cost,N,0,true,memo));

}