×

# ZCO12004 - Round Table

 0 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[i]; if(first == true) return 0; if(first == false) return cost[i]; } if(prev) { if(memo[i][0]) return memo[i][0]; else memo[i][0] = min ( cost[i] + minCost(cost,N,i+1,prev,memo) , minCost(cost,N,i+1,!prev,memo)); return memo[i][0]; } else { if(memo[i][1]) return memo[i][1]; else memo[i][1] = cost[i] + minCost(cost,N,i+1,!prev,memo); return memo[i][1]; }  } int main() { int N; cin>>N; int cost[N]; for(int i=0 ; i>cost[i]; int memo[N][2]; for(int i=0 ; i
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,093
×1,901
×423
×311
×74
×1

question asked: 27 Nov '18, 21:42

question was seen: 68 times

last updated: 27 Nov '18, 21:42