A General Dynamic Programming Approach to the Optimal Water Storage Management for Irrigation