517 Super Washing Machines
1. Question
You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty.
For each move, you could choose any m(1 ≤ m ≤ n) washing machines, and pass one dress of each washing machine to one of its adjacent washing machines at the same time.
Given an integer array representing the number of dresses in each washing machine from left to right on the line, you should find the minimum number of moves to make all the washing machines have the same number of dresses. If it is not possible to do it, return -1.
Example1
Example2
Example3
Note:
The range of n is [1, 10000].
The range of dresses number in a super washing machine is [0, 1e5].
2. Implementation
(1) Math
思路: 这题其实不算DP,更多是数学问题。具体思路可参考https://blog.csdn.net/tstsugeg/article/details/62427718
3. Time & Space Complexity
Math: 时间复杂度O(n), 空间复杂度O(n)
Last updated
Was this helpful?