Emptying the Glasses
Time limit2sMemory limit32 MB
Given N glasses and pairwise pour costs, find the minimum effort to end with water in at most K glasses.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Graph, Bit manipulation, Shortest path
- Solved
- No attempts yet
Problem
Mislav has glasses of unlimited volume, and every glass holds some water. He wants to drink all of the water, but he does not want to drink from more than glasses. The only thing he can do is pour all of the water from one glass into another glass.
The glasses are not all the same distance away from him, so the choice of glasses matters. Pouring the water from glass into glass costs effort.
Find the smallest total effort needed to leave water in at most glasses.
Input
The first line contains the integers and ().
Each of the next lines contains integers. The -th number on the -th line is (). holds for every .
Output
Print the minimum total effort on one line.
Hint
If at most glasses hold water from the start, no pouring is needed and the answer is 0.
Water may travel through several glasses. Mislav can pour glass into glass , then later pour glass into glass .