"BZOJ-1055" Toy name range DP

Source: Internet
Author: User

1055: [HAOI2008] Toy name time limit:10 Sec Memory limit:162 MB
submit:1560 solved:907
[Submit] [Status] [Discuss] Description someone a set of toys, and the idea of naming toys. First he chooses any one of the four letters of wing as the basic name of the toy. Then he will, according to his preference, use any of the letters in the name "WING" to replace any of the two letters, so that his name can be extended very long. Now, he would like to ask you to guess a very long name, which may have been initially distorted by which letters. Input first line four integers w, I, N, G. Indicates that each letter can be replaced by a few two letters. The next W line, two letters per line, indicates that W can be substituted with these two letters. Next I line, two letters per line, indicating I can be replaced with these two letters. The next n lines, two letters per line, indicate that n can be substituted with these two letters. The next G line, two letters per line, indicates that G can be substituted with these two letters. The last line is a string that does not exceed Len in length. denotes the name of the toy. The Output line string, which may be distorted by which letters. (output in the order of wing) if the given name cannot be distorted by any one letter, then output "The name is wrong!" Sample Input1 1 1 1
Ii
Ww
Ww
IG
IIIISample OutputinchHINTW can become II so IIII can be shrunk into WW in can become WW so WW can be shrunk to I or n so the final answer should be in the order of "WING"
Output in
[Data Range]
100% data satisfies len<=200,w, I, N, g<=16sourcesolution

Interval DP

Violent transfer can be ... is 10 times slower than others.

F[L][R][K] Indicates whether [L,R] can be pressed into k

Then enumerate the interval lengths, enumerate the left endpoints, enumerate wing, enumerate each of the indents of wing, enumerate breakpoints

Anyway, it's a violent diversion, and then it's fine.

Code
#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<map>using namespacestd;Chars[5][ -][3],s[ About],n[5],c[5];map<Char,int>MP;BOOLf[ About][ About][5];intMain () {scanf ("%d%d%d%d", &n[1],&n[2],&n[3],&n[4]); mp['W']=1, mp['I']=2, mp['N']=3, mp['G']=4; c[1]='W', c[2]='I', c[3]='N', c[4]='G';  for(intI=1; i<=4; i++)         for(intj=1; j<=n[i]; J + +) scanf ("%s", s[i][j]+1); scanf ("%s", s+1);intLen=strlen (s+1);  for(intI=1; i<=len; i++) f[i][i][mp[s[i]]]=1;  for(intI=2; i<=len; i++)         for(intj=1; j<=len; J + +)            if(j+i-1<=Len) {                    intl=j,r=j+i-1;  for(intk=1; k<=4; k++)                         for(intL=1; l<=n[k]; l++)                             for(intM=l; m<r; m++) F[l][r][k]|= (f[l][m][mp[s[k][l][1]] & f[m+1][r][mp[s[k][l][2] ]]); }     for(intI=1; i<=4; i++)if(f[1][len][i]) Putchar (C[i]); if(!f[1][len][1] &&!f[1][len][2] &&!f[1][len][3] &&!f[1][len][4]) puts ("The name is wrong!"); return 0;}

"BZOJ-1055" Toy name range DP

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.