hdu2476--string Painter

Source: Internet
Author: User

String Painter Time limit:5000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1834 Accepted Submission (s): 814


Problem Descriptionthere is strings A and B with equal length. Both strings is made up of lower case letters. Now you have a powerful string painter. With the "help of the painter", you can change a segment of characters of a string of all other character you want. That's, after using the painter, the segment are made up for only one kind of character. Now the your task is to the change A to B using string painter. What ' s the minimum number of operations?
Inputinput contains multiple cases. Each case consists of lines:
The first line contains string A.
The second line contains string B.
The length of both strings would not be greater than 100.

Outputa single line contains one integer representing the answer.
Sample Input
Zzzzzfzzzzzabcdefedcbaababababababcdcdcdcdcdcd

Sample Output
67

Source2008 Asia Regional Chengdu
Recommendlcy | We have carefully selected several similar problems for you:2480 2481 2478 2482 2475

Statistic | Submit | Discuss | Note


Interval DP, the problem is very special Ah, first consider from the empty string into a second string, and then use this information to calculate the first string into a second string of the minimum number of times


#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring># Include <iostream> #include <algorithm>using namespace std;const int N = 110;const int inf = 0x3f3f3f3f;int dp[ N][n];int F[n];char Stra[n], Strb[n];int main () {while (~scanf ("%s%s", Stra + 1, STRB + 1)) {int N = strlen (stra + 1); memset (DP, 0, sizeof (DP)), memset (f, INF, sizeof (f)), for (int i = 1; I <= n; ++i) {dp[i][i] = 1;} for (int i = n; i >= 1; i.) {for (int j = i + 1; j <= N; ++j) {Dp[i][j] = dp[i + 1][j] + 1;for (int k = i + 1; k < = J; ++k) {if (strb[k] = = Strb[i]) {dp[i][j] = min (Dp[i][j], dp[i + 1][k] + dp[k + 1][j]);}}} F[0] = 0;for (int i = 1; I <= n; ++i) {f[i] = dp[1][i];} for (int i = 1; I <= n; ++i) {if (stra[i] = = Strb[i]) {f[i] = f[i-1];} else{for (int j = 0; J < i; ++j) {F[i] = min (F[i], f[j] + dp[j + 1][i]);}} printf ("%d\n", F[n]);} return 0;}


hdu2476--string Painter

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.