found algorithm.
someday I will write detail of this problem.
my code is here
int c, l; int Bridge(int[] t) { l=t.length; Arrays.sort(t); while(l>3) { c+= Math.min( 2*t[1], t[l - 2] + t[0]) + t[l-1] + t[0]; l-=2; } return c+= l<3?t[l-1]:t[1] + t[0]+t[2]; }
https://codefights.com/challenge/K4HYozLrbRoLHkt8P
No comments:
Post a Comment