BZOJ2423 [HAOI2010] Longest common sub-sequence

Source: Internet
Author: User

The first question is bare dp ....

Second question or bare DP, note a special case (I forgot what the special case was QAQQQ)

The scrolling array can be pressed off one dimension, and ^ (XOR) ratio! (not) Slow ...

1 /**************************************************************2 problem:24233 User:rausen4 language:c++5 result:accepted6 time:964 Ms7 memory:892 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <cstring> A#include <algorithm> -    - using namespacestd; the Const intN =5005; - Const intMoD =100000000; - intf[2][n], g[2][n]; - intL1, L2, Cur, I, J; + CharS1[n], s2[n]; -    + voidRead () { A     CharCH =GetChar (); at      while(Ch <'A'|| CH >'Z') && ch! ='.') -CH =GetChar (); -      while(ch! ='.') -S1[++L1] = ch, ch =GetChar (); -CH =GetChar (); -      while(Ch <'A'|| CH >'Z') && ch! ='.') inCH =GetChar (); -      while(ch! ='.') toS2[++L2] = ch, ch =GetChar (); + } -    the intMain () { * read (); $      for(j =0; J <= L2; ++j)Panax Notoginsengg[0][J] =1; -g[1][0] =1; theCur =0; +      for(i =1; I <= L1; ++i) A          for(j =1, cur ^=1; J <= L2; ++j) the             if(S1[i] = =S2[j]) { +F[CUR][J] = f[!cur][j-1] +1; -G[CUR][J] = g[!cur][j-1]; $                 if(F[cur][j] = = F[cur][j-1]) $G[CUR][J] + = g[cur][j-1], G[cur][j]%=MoD; -                 if(F[cur][j] = = f[!cur] [j]) -G[CUR][J] + = G[!cur][j], g[cur][j]%=MoD; the}Else{ -F[CUR][J] = F[!cur][j], g[cur][j] = g[!cur] [j];Wuyi                 if(F[cur][j] < f[cur][j-1]){ theF[CUR][J] = f[cur][j-1]; -G[CUR][J] = g[cur][j-1]; Wu}Else if(F[cur][j] = = F[cur][j-1]){ -G[CUR][J] + = g[cur][j-1]; About                     if(F[!cur][j-1] ==F[cur][j]) $G[CUR][J]-= g[!cur][j-1]; -G[CUR][J]%=MoD; -                 } -             } Aprintf"%d\n%d\n", F[cur][l2]% mod, G[CUR][L2]%MoD); +     return 0; the}
View Code

BZOJ2423 [HAOI2010] Longest common sub-sequence

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.