Dynamic programming - optiaml rute time

Input:4 - number of stations3 - number of changes between stations15 3 2 10 7 - time of traveling betwen bus station2 25 30 1 10 - time of traveling betwen railway station7 10 5 1 - time to travel from bust station to railwey station10 8 5 5 - time to travel form railwey station to bus station

Output:33

I need to solve the problem using dynamic programming.I write some code in ansi C that works properly but for input files with number of stations larger than 100 the algorithm becoming very very slov. How to solve the task properly? Any Tips?