Background
For hundreds of years fire departments all over the world have been using water for their fight against the fire. Unfortunately, one cannot always find enough water right where the fire is burning. Accordingly, the fire departments are equipped with lots of pumps and pipes to transport the water to where it is needed.Setting up the system of pumps and pipes might not be such an easy task, as there are several restrictions one has to take care of.
The Problem
Let us assume that only one type of pipes is used for the transportation of water, namely pipes with a diameter of 75 millimeters and a length of 20 meters. Depending on the quantity of water that is pumped through the tubes, there is a loss of pressure per meter according to the following table:
flow (f) in liters per minute loss of pressure in millibar per meter
200 1
400 3
600 6
800 10
1000 15
1200 20
The pressure is also affected by the profile of the landscape, more precisely the pressure changes by 1 bar every 10 meters of vertical distance, decreasing for pipes running uphill and increasing for pipes running downhill. Pumps need an input pressure of at least 2 bar and produce a constant output pressure of 8 bar, but they cannot be used to reduce pressure. Pipes do not resist a pressure higher than 12 bar, and for a constant flow a pressure of at least 2 bar is needed at all points. At the end of the line, the pressure must be at least 5 bar and at most 8 bar to permit effective fire fighting. There is always a pump at the beginning of the line of pipes (position 0). Other pumps can be placed wherever two pipes are attached to each other but not at the end.
Write a program to find the least number of pumps necessary, and their positions. If several solutions with the least number of pumps exist, prefer the ones where pumps are placed closer to the beginning of the line (carrying these pumps is no fun. . . ).