UVa 116 unidirectional TSP (DP)

Source: Internet
Author: User
Tags require

116-unidirectional tsptime limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_ problem&problem=52


Problems that require minimum paths through some domain appear in many different of areas. For example, one of the constraints in VLSI routing problems is minimizing wire length. The Traveling Salesperson Problem (TSP)--finding whether all the cities in a salesperson ' s route can be visited exactly Once with a specified limit in travel time--is one of the canonical examples of a np-complete problem; Solutions appear to require a inordinate amount to generate, but are simple to check.

This is problem deals with finding a minimal path through a grid of points-while traveling-

The Problem

Given an

Matrix of integers, you are to write a program that computes a path of minimal weight. A path starts anywhere in column 1 (the "a") and consists of a sequence of steps terminating in column n (The last column). A step consists of the traveling from column I to column i+1 in A adjacent (horizontal or diagonal) row. The I and Last rows (rows 1 and m) of a matrix are considered adjacent, i.e., the matrix ' wraps ' Represents a horizontal cylinder. Legal steps are illustrated below.

The weight of a path is the sum of the ' integers in each of the ' N cells of the matrix that are visited.

For example, two slightly different

Matrices are shown below (the only difference are the numbers in the bottom row).

The minimal path is illustrated to each matrix. Note This path for the matrix on the right takes advantage of the the Adjacency property of the The "the" and last rows.

The Input

The input consists of a sequence of matrix specifications. Each matrix specification consists of the "row and column dimensions in" on "a line" followed by

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.