LightOJ1025 The Specials Menu (interval dp)

Source: Internet
Author: User

Give a string, ask there are several ways to delete characters so that the deleted non-empty string is a palindrome string.

Of course the interval dp:DP[I][J] Indicates the number of STRI...STRJ of the substring

Feel bad transfer, may repeat forget. I hand over the "AAA" this data, and then the way to move:

D[I][J] =∑d[i '][j ']+1 (i<=i ' <=j ' <=j and Str[i]==str[j])

This interval DP is the same as the classical example of adjacent stones, enumeration length and then the lifting point, so as to ensure the topological order of the computational process. Time complexity O (STRLEN4).

1#include <cstdio>2#include <cstring>3 using namespacestd;4 Charstr[ the];5 Long Longd[ the][ the];6 intMain () {7     intT;8scanf"%d",&t);9      for(intCse=1; cse<=t; ++CSE) {Tenscanf"%s", str); One         intn=strlen (str); Amemset (D,0,sizeof(d)); -          for(intlen=1; len<=n; ++Len) { -              for(intk=0; k+len<=n; ++k) { thed[k][k+len-1]=Len; -                  for(intI=0; i<len; ++i) { -                      for(intj=i+1; j<len; ++K) { -                         if(Str[k+i]!=str[k+j])Continue; +d[k][k+len-1]+=d[k+i+1][k+j-1]+1; -                     } +                 } A             } at         } -printf"Case %d:%lld\n", cse,d[0][n-1]); -     } -     return 0; -}

LightOJ1025 The Specials Menu (interval 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.