Блог пользователя wizard_18

Автор wizard_18, история, 5 лет назад, По-английски
  • Проголосовать: нравится
  • -7
  • Проголосовать: не нравится

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

You can check-out my submission. I used dynamic programming.

https://codeforces.me/contest/1506/submission/111002216

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    what was your intuition behind this approach? basically what is the overlapping subproblem in this solution?

    • »
      »
      »
      5 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится +6 Проголосовать: не нравится

      The idea was to find the answer if the string was to end at ith index such that s[i] = '*'.

      dp[i] represents the minimum number of replacements for the prefix s[0]....s[i] where s[i]='*'.

      dp[index of first occurrence of '*' in s] = 1 (base condition).

      The transition is pretty simple, if s[i]='*', and because it is the last character of our prefix, we will have to change it to 'x'.

      So we traverse over all the previous indices 'j' of s such that s[j]='*' and (i — j)<=k (due to the range given) and do the transition dp[i]=min(dp[i],dp[j]+1) (+ 1 because we are replacing the current character to 'x' as well).

      Our final answer will be dp[index of last '*' character in s].

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

Here's a recursive DP approach , I think it is pretty intuitive.

https://codeforces.me/contest/1506/submission/111108103

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My submission with explanatory comments