The paper presents the problem of optimizing investments in rail-highway crossings. The optimization problem is to allocate limited available funds to minimize the expected number of traffic accidents. This problem is treated as an optimal resource allocation problem and is solved by the Dynamic Programming method. The method is used to solve a real problem of investment optimization in the Yugoslav railway system.