Algorithm title: UVA 10635 Prince and Princess (DP + LCS)

Source: Internet
Author: User

In a n x n chessboard, Prince and Princess plays a game. The squares in the chessboard are numbered 1, 2, 3 ... n*n, as shown below:

Prince stands in square 1, make p jumps and finally reach Square n*n. He enters a square at most once. So if we do xp to denote the p-th Square he enters, then x1, x2, ... x p+1 are all different. Note that x1 = 1 and xp+1 = N*n. Princess does the similar thing-stands in square 1, make Q jumps and finally reach Square n*n . We use y1, y2 , ... yq+1 to denote the sequence, and all q+1 number s are different.

Figure 2 belows show a 3x3 Square, a possible route for Prince and a different route for Princess.

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.