Purchase Solution

Dynamic Programming Algorithm to Find Minimum Cost

Not what you're looking for?

Ask Custom Question

You are going on a long horse trip. You start on the road at mile post 0. Along the way there are n horse stations at mile posts m1 < m2 <. mn where each mi is measured from the starting point. The only places you are allowed to stop and change horses are at these stations, but you can choose which of the stations you stop at. You must stop at the final station (at distance mn), which is your destination.

Assume that at a station ti takes 2 hours to change horses and a horse takes (x ln x)/100 hours to travel x miles. Design a dynamic programming algorithm to determine a sequence of stations at which to stop so as to minimize the total hours.

Example:
Number of mile posts (not including post 0): 5
Enter mile posts: 50
250
325
680
850
The minimum time is 50.000000
Stops: 5 4 3 0.

Purchase this Solution

Solution Summary

The solution designs a dynamic programming algorithm to determine a minimum cost. Attachment is by Java.

Solution Preview

This dynamic algorithm is implemented by Java. Please see the attachment.

// HorseTrip.java

import java.util.Scanner; // To get input data
import java.util.Set;
import java.util.TreeSet;
import java.util.Collections;
import java.util.Iterator;

public class HorseTrip {
private double[] miles;
private Set <Integer> stops;

public HorseTrip() {
stops = new TreeSet<Integer>();
// Get input data
Scanner scanner = new Scanner(System.in);
System.out.print("Number of mile posts (not including post 0): ");
int n = ...

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Javscript Basics

Quiz on basics of javascript programming language.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.