Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

wonderful_trip's blog

By wonderful_trip, history, 12 months ago, In English

I'm doing an exercise on expected value. In problems that calculate the expected value of the number of steps to do something, the formula f(state) = 1 + sum of (f(next state) * p(next state)) is often used. where state is the current state, the next state is the new state that can be obtained from the current state, p(next state) is the probability of a new state occurring from the current state. But I just memorized it and applied it like a parrot and always wondered how the formula was proven or built.

I've tried to find this recipe internet before, but I haven't been able to find anywhere that goes into detail about it.

Can someone explain it to me.

Thanks for help!!! Sorry for my bad English.

Full text and comments »

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

By wonderful_trip, history, 15 months ago, In English

I have 1 problem: There are n flower shops, the i-th shop sells ki different kinds of flowers. Need to buy n types of flowers from n given shops, each shop buys 1 type of flowers, so that n types of flowers after purchase are distinguished.

. n <= 2000 . ki <= 5

can someone help me with an idea to solve this problem.

thanks for help !!!

Full text and comments »

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

By wonderful_trip, history, 3 years ago, In English

I'm training on Lightoj. And I have trouble in post: https://lightoj.com/problem/politeness. Can anyone give me an idea to solve this problem?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By wonderful_trip, history, 3 years ago, In English

When I do an exercise I have a problem that let Ai <= 60 and n <= 1e5 and q <= 1e5, Count number of distinct elements in l to r. With type 1 query update change all elements from l to r to v. Type 2 query answer the number of distinct elements from l to r.

Example:

5 5

1 1 1 1 1

1 2 4 2

1 5 5 3

2 1 5 // is 3.

2 1 4 // is 2.

2 2 4 // is 1.

I know how if we update an element we can do this with the segment tree. But i don't know updating the range. Is this possible? if yes please explain to me. thanks for help!

Full text and comments »

By wonderful_trip, history, 3 years ago, In English

I just made a mistake while participating in a coding contest in Vietnam and I came across a simple dp problem, the problem was: https://lqdoj.edu.vn/problem/dutpc2a : test of the contest organizers that I participated in, https://atcoder.jp/contests/dp/tasks/dp_h: The problem I encountered is the same as the one on atcoder

But I accepted this problem on atcoder but when I submitted the test from the contest organizer that I joined, I was wrong. And the problem I have is when I compare with the character '.' I got wrong but compare with '#' then accepted. Can someone explain to me why when I compare the character '.' wrong?

I think there are a few caveats when compared to the '.' and some other special characters, if my thinking is correct, someone can explain it to me.

this my code wrong:

char v[nax][nax]; int dp[nax][nax];

int32_t main() {

FASTIO

int n, m;

cin >> n >> m;

for (int i = 1; i <= n; ++i) {
  for (int j = 1; j <= m; ++j) {
    cin >> v[i][j];
  }
}
for (int i = 1; i <= n; ++i) {
  for (int j = 1; j <= m; ++j) {
    if (i == 1 && j == 1)
    {
      dp[i][j]=1;
    }
    else
      if (v[i][j] == '.')
      {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
      }
  }
}
cout << dp[n][m];
return 0;

}

and my code accepted:

char v[nax][nax]; int dp[nax][nax];

int32_t main() {

FASTIO

int n, m;

cin >> n >> m;

for (int i = 1; i <= n; ++i) {
  for (int j = 1; j <= m; ++j) {
    cin >> v[i][j];
  }
}
for (int i = 1; i <= n; ++i) {
  for (int j = 1; j <= m; ++j) {
    if (i == 1 && j == 1)
    {
      dp[i][j]=1;
    }
    else
    {
      if (v[i][j] != '#')
      {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
      }
    }
  }
}
cout << dp[n][m];
return 0;

}

Thanks for the help and sorry for my english!

Full text and comments »

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

By wonderful_trip, history, 3 years ago, In English

When learning about 2D BIT, I have the question that 2D BIT can be easily updated 1 element and get sum, but can update the range ?

Problem:

for each query, you need to update the rectangle (x, y, u, v) each coordinate of a rectangle with upper left corner (x, y) and lower right corner being (u, v) incremented by c "at the same time".

After the update, we can find the sum query (x1,y1,x2,y2);

For example:

Sum(2,3,3,4) is 28;

Is it possible to solve this problem? If so, please show how to do it!!!

thanks for help!!!

Full text and comments »

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

By wonderful_trip, history, 3 years ago, In English

I just know how to find LCS use dynamic programming:

if (s1 [i] == s2 [j]) dp [i] [j] = dp [i-1] [j-1] +1; else dp [i] [j] = max (dp [i-1] [j], dp [i] [j-1]).

But I have trouble with problem: Find LCS with s1 <= 1e6 and s2 > 1e3. What is the best way to find LCS? Thanks for help!!!

Full text and comments »

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