Repair Work

2

3 votes
Dynamic Programming, Open, Approved, Math, Medium
Problem

Harsh is a lazy person.He loves watching t.v ,eating and sleeping.Nothing else gives him more joy than these things. On one fine sunday morning his mom decided to end his laziness and gave him a task.

Harsh was supposed to mend the broken windows of his house.The windows were numbered from 1 to n.Some of the windows were good while some were broken.The cost to mend the windows from ith to jth index (i<=j) was sqrt(j-i+1).Harsh was supposed to mend the windows in the minimum possible cost.The window is represented as a string consisting of 0 and 1 where 0 denotes a broken window while 1 denotes a good window.

Since he was a lazy person he asks you to calculate the minimum cost for repairment .

Input:

The first line contains N i.e. the size of the window.The second line contains a string of size N representing the state of the window.

Output:

The minimum cost required to mend the entire window.The output should be rounded to 4 decimal places.

Constraints:

1<=N<=5000

Sample Input
9
010111110
Sample Output
2.7321
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?