Tuesday, 27 May 2014

Easy/Cakewalk DP on topcoder :- PROBLEM LINK SRMCARDS
naive approach would be
algorithm :-
BEGIN 
//declare a boolean array ar[500]
//initialize elements with false 
for i in range (0,cards.size())
    ar[cards.begin()+i]=true  
for i in range (0,500)
    if ar[i]== true
       then ar[i-1]=false
            ar[i+1]=false
count=0
for i in range (0,500)
    if ar[i]==true 
       then count=count+1
       
return count  
END 

it was very clear how to consider states in this problem and approach from other end is also equally correct i also feel that ar[i-1]=false can be omitted , 1D -DP is very clear now but lets face some more questions ah that hackerrank question still undone :(
end sems almost over Discrete structures paper remains for tomorrow and haven't even touched it properly :P just being a bit lazy with acads .

No comments:

Post a Comment