Help in finding fault in my approach.

Правка en1, от glow, 2016-08-20 21:33:59

Hi, I was solving Hard Problem and my approach is :

If string[i] <= string[i+1] than continue;

Else :

If  string_rev[i] < string[i+1] c1=cost[i] Else c1=inf;

If string[i] < string_rev[i+1] c2=cost[i+1] Else c2=inf;

If string_rev[i] < string_rev[i+1] c3=cost[i]+cost[i+1]; Else c3=inf;

if(c1<=c2 && c1<=c3 && c1!=inf) ans+=c1; If(c1==c2)a[i+1]=min(a[i+1],b[i+1]);;

else if(c2<=c1 && c2<=c3 && c2!=inf) ans+=c2; a[i+1]=min(a[i+1],b[i+1]);

else if(c3<=c1 && c3<=c2 && c3!=inf) ans+=c3; a[i+1]=min(a[i+1],b[i+1]);

Code Link.

Can you please help me in finding fault in this approach ?

Теги #dp, debug, help

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский glow 2016-08-20 21:35:08 32
en1 Английский glow 2016-08-20 21:33:59 760 Initial revision (published)