Status compression DP poj 1699 solution report

Source: Internet
Author: User

Http://acm.pku.edu.cn/JudgeOnline/problem? Id = 1699

Today, when I was doing poj 1699, I obviously felt that DP could be used to solve the problem, but I still could not find the proper state equations and substructures. In discuss, we can see that it is more convenient to solve the problem by using "State compression DP". So we spent an afternoon searching for State DP data. In the previous article (zz) I saw a very detailed introduction and began to analyze poj 1699.

The first intuition of this question is that all strings are arranged in full. We can certainly find the optimal solution through backtracking, but the time complexity may not be AC. So I tried to find the optimal sub-structure and try to use DP to solve the problem.

If Min is the optimal solution, the most direct consideration is Min = min {the string length obtained when the I-th string is at the end }.

Assume that DP [Si] [I] indicates the optimal value (best sequence) ending with an I string in Si state, where Si is a set represented by binary bits, the length of the binary string (LEN (SI) is determined by N according to the number of strings. If Si [k] = 0, it indicates that the current State set does not contain the string K, that is, the k-th string has not been placed. k is used! = SI.

For example, n = 4, SI = 00000 ~ 01111.

Then min = min {DP [2 ^ n-1] [I]},

N indicates the number of strings, 0 <I <n.

2 ^ n-1 indicates that all strings have been placed,

DP [2 ^ n-1] [I] indicates that the string length ends with string I when all strings have been placed.

DP [Si] [I] = min {DP [SJ] [J] + M (I, j )},

SJ = SI &(~ (1 <I) indicates that the current State is set out of I, and a smaller subproblem SJ is obtained.

For every J that belongs to SJ, find the sub-problem DP [SJ] [J].

There are many repeated sub-problems, such as when Si = 01101, I = 0, then SJ = 01100, then J = 2, j = 3 belong to the set SJ, because both SJ [2] and SJ [3] are 1.

To solve DP [S0] [0], you need to solve DP [s2] [2] and DP [S3] [3].

When Si = 01110 and I = 1, SJ = 01100, therefore, DP [S1] [1] also requires DP [s2] [2] and DP [S3] [3].

Considering the above recursive form and repetition subproblem, we consider using the memory dp (memory recursive search) to solve the problem.

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.