1351 dp in the range of ultraviolet

Source: Internet
Author: User

1351 dp in the range of ultraviolet
Ultraviolet A 1351-String Compression

 

Ask how short a string can be after compression. The compression rule is that if there is a continuous repeated substring (for example, abcabcabcad), it can be compressed into the number of duplicates + (repeated substring) (in the preceding example, the answer is 3 (abc) ad ). The length of the compressed string must contain digits and parentheses.


Range dp, dp stores the minimum length that can be compressed in this range.
Each interval can be divided into two subintervals, or the interval can be compressed. The Preprocessing result shows that each interval can contain up to several substrings: c [I] [j].

Dp [I] [j] = min {dp [I] [k] + dp [k] [j], digits (s) + dp [I] [l] + 2 };
L = (j-I + 1)/c [I] [j];
S = c [I] [j];

The Preprocessing of the c array can be completed by O (n ^ 3. Enumerate the length and start position of the duplicate substring, and then find it from the start position. For each string found, c [I] [j] + 1. For details, see the code.

 

 

 

#include 
 
  using namespace std;const int INF = 999999999;int len;char s[205];int _c[205][205];int dp[205][205];int _degits(int num) {int cnt = 0;while (num) {cnt++;num /= 10;}return cnt;}void _solve() {for(int i=0; i
  
   0; T--) {scanf (%s, s);len = strlen(s);_solve();for (int i=0; i
   
    =0; i--) {dp[i][j] = INF;for (int k=i; k
    
     

 

 

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.