laxmi-hari's blog

By laxmi-hari, history, 8 months ago, In English

friends , few days ago i was doing a problem but certainly i lost its link

question is :: given a string and in one operation we can swap adjacent characters only .

what to do :: find minimum number of operation so that given string will be reversed.

help me to get way to solve it , it is really a good problem.

Full text and comments »

  • Vote: I like it
  • +9
  • Vote: I do not like it

By laxmi-hari, history, 9 months ago, In English

which condition should i add?

this code is for count of palindrome subsequences (need not to be distinct )

long long int countPS(string s) { ll n = s.length();

vector<ll> dp(n , 0) , next(n , 0);

    for(ll i=n-1; i>= 0; i--)
    {
        for(ll j=i; j<n; j++)
        {
            if(i == j)
              dp[j] = 1;

            else if(s[i] == s[j])
              dp[j] = (next[j] + dp[j - 1] + 1) % mod;

            else
              dp[j] = ((next[j] + dp[j - 1] - next[j - 1]) % mod + mod) % mod;
        }

        next = dp;
    }

    return next[n- 1];

}

which condition should i add to this code i can get count of distinct plaindromic subsequences

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it