HDU 4433 locker (12 years in Tianjin, DP)

Source: Internet
Author: User

Reprinted please indicate the source, thank youHttp://blog.csdn.net/ACM_cxlove? Viewmode = Contents
By --- cxlove

Question: two strings are given. You can select 1-3 consecutive numbers, add 1 at the same time or subtract 1 at the same time, and ask the minimum number of operations to convert one string to another.

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4433

BFS can have similar questions in the past.

However, the data volume of this question is too large, and many of them have been searched.

I wrote a search for Objective B, but it was suspended and no optimization was added.

During the training, the DP Solution of yobobo was very similar, but it seems to be stuck in the Post-efficiency?

DP [I] [J] [k] indicates that the first I has been completely matched. At this time, the I + 1 has been added with J bits, K has been added for the I + 2 bits.

Transfer is divided into two steps: enumeration plus, enumeration Subtraction

Note: If the I-th vertex adds a, the I + 1-th vertex adds B, and the I + 2-th vertex adds C, the relation A> = B> = C cannot be wrong.

# Include <cstdio> # include <cstring> # include <algorithm> # include <iostream> # define INF 1 <20 # define n 1005 using namespace STD; char S1 [N], S2 [N]; int DP [N] [10] [10]; int main () {While (scanf ("% S % s ", s1, S2 )! = EOF) {int L = strlen (S1); For (INT I = 0; I <= L; I ++) for (Int J = 0; j <10; j ++) for (int K = 0; k <10; k ++) DP [I] [J] [k] = inf; DP [0] [0] [0] = 0; For (INT I = 0; I <L; I ++) for (Int J = 0; j <10; j ++) for (int K = 0; k <10; k ++) {int t = (s2 [I]-S1 [I]-J + 20) % 10; for (int A = 0; A <= T; A ++) for (INT B = 0; B <= A; B ++) DP [I + 1] [(K + a) % 10] [B] = min (DP [I + 1] [(K + a) % 10] [B], DP [I] [J] [k] + T); t = (10-t) % 10; for (int A = 0; A <= T; A ++) for (INT B = 0; B <= A; B ++) DP [I + 1] [(k-A + 10) % 10] [(10-b) % 10] = min (DP [I + 1] [(k-A + 10) % 10] [(10-b) % 10], DP [I] [J] [k] + T);} printf ("% d \ n", DP [l] [0] [0]);} return 0 ;}

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.