Repair Work
Practice
2 (3 votes)
Dynamic programming
Open
Approved
Math
Medium
Problem
74% Success 767 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
14 votes
Tags:
Counting and ArrangementsDynamic programmingAlgorithmsMediumDynamic Programming
Points:20
117 votes
Tags:
ApprovedEasyMathNumber TheoryOpen
Points:30
4 votes
Tags:
AlgorithmsDynamic ProgrammingCounting and Arrangements