[DP] [P5615] [MtOI2019] jump time

Description

Given \ (n-\) edges, the \ (I \) length sides is \ (I \) , each edge has \ (50 \% \) probability is selected, the selected edge if required can be composed of a plane convex polygon, the number of weighting schemes is a scheme sides, or a weight of \ (0 \) . Modulo large prime number expected value required weights.

There are (T \) \ set of data.

Limitations

\ (1 \ leq n \ leq T \ leq 5000 \)

Solution

Since \ (\ mathsf {\ color { black} d} \ mathsf {\ color {red} {isangan233}} \) in yLOI time with the practice of the penultimate gear sub-tasks over C title , so I have to at MtOI practice with the penultimate sub-file tasks had lost his C title

Note that since the probability of all cases are the same, so just requires the total number of sides in all cases, divided by \ (2 ^ n \) is the expectation.

Consider DP.

According to a theorem of plane geometry, for \ (n-\) line segments, they can form a plane convex polygon necessary and sufficient condition that any \ ((n-1) \ ) length is greater than the remaining line segments of a segment length.

It can justify the shortest line between two points by attained the axioms, the adequacy of the number of segments can be selected mathematical induction.

Inference obtained: For this question, the selected side can be composed of convex polygons and Sufficient Conditions plane is the longest side of a length less than the lengths of the other sides.

The proof, consider the longest side into the other side, the edge length becomes smaller, and the remaining length of the large side, will not change the direction of the inequality sign.

Set \ (F_i \) is the length of all edges does not exceed \ (I \) number of all case sides can be constructed convex polygon and when.

Consider a case where these divided into two categories, the first category is not included in length \ (I \) of the edge of the case, the second category is a length \ (I \) the case of edge.

For the first category, and the number of sides is \ (F_ {I -. 1} \) .

For the second type of situation, considering the rest of the long side length is greater than the sum of \ (I \) can.

Set \ (G_J \) is selected from at least two sides of the edge and a length and \ (J \) (without convex polygon configuration required) in all cases and the number of sides, \ (h_j \) is selected from at least two sides, and and the length of the side is \ (J \) total number of cases (with no claim constitute convex polygons). These two values selected require no more than the length of the side of the \ (I \) , the first dimension is actually omit these two values.

So there

\[f_{i} = f_{i - 1} + \sum_{j = i + 1}^{i^2} (g_j + h_j)\]

Here plus \ (h_j \) because for each case can add a length \ (I \) side to form a convex polygon, for all cases, each case can add an edge, can be added to a total of \ (h_j \) edges, and \ (g_j \) is the case of the original number of sides.

Consider recursive \ (g \) and \ (H \) .

Consider ascending enumeration \ (I \) , i.e., upper side length is increased, \ (G \) and \ (H \) changes.

For \ (G_J \) , all optionally and right sides and the two sides of \ - ((j i) \ ) situations, this edge may be added to the right side and to achieve \ (J \) , and also there is not opted length \ (I \) side of this situation, it is

\[g_j = g_j + g_{j - i} + h_{j - i}~~~~~(j > i)\]

Of course, for the selected \ (I \) and the other side of the case, it is possible to \ (G \) generating contributions, therefore

\[g_{j + i} = g_{j + i} + 2~~~~~~(j < i)\]

To \ (h \) recurrence empathy:

\[h_j = h_j + h_{j - i}~~~~~(j > i)\]

\[h_{j + i} = h_{j + i} + 1~~~~~(j < i)\]

Then the resulting \ (\ G) and \ (H \) recursive \ (F \) can.

Consider Complexity: sum of all edges are \ (O (n ^ 2) \) level, therefore each update \ (G \) and \ (H \) are \ (O (n ^ 2) \) of a total update \ (O (n) \) times, updating \ (G \) and \ (H \) of the overall complexity \ (O (n-^. 3) \) . And recursive \ (F \) each time is \ (O (n ^ 2) \) , a total update \ (O (n) \) times, so also the complexity of the \ (O (n ^ 3) \) . Therefore, the total time complexity \ (O (n-^. 3) \) , the former by \ (4 \) subtasks.

However, we note that the space complexity is \ (O (n ^ 2) \) , so for the first \ (5 \) subtasks, our space is fully able to withstand, and the time complexity is still polynomial, and therefore local hook playing table can by subtask \ (5 \) , the length of the table is \ (48K \) , do not even need to use encryption to shorten the code characters, direct deposit to the plaintext.

Code

#include <cstdio>
#include <algorithm>

const int maxn = 100005;
const int MOD = 1000000007;
const int MODP = 1000000005;

int T, N;
int query[maxn];
ll frog[maxn], gorf[maxn], h[maxn];

ll mpow(const ll x, int y);

int main() {
  freopen("1.in", "r", stdin);
  qr(T);
  for (int i = 1; i <= T; ++i) {
    qr(query[i]);
    N = std::max(N, query[i]);
  }
  gorf[3] = 2; h[3] = 1;
  for (int i = 3, upceil = 3; i <= N; ++i) {
    for (int j = i + 1; j <= upceil; ++j) {
      (frog[i] += gorf[j] + h[j]) %= MOD;
    }
    (frog[i] += frog[i - 1]) %= MOD;
    upceil += i;
    for (int j = upceil; j >= i; --j) {
      (gorf[j] += gorf[j - i] + h[j - i]) %= MOD;
      (h[j] += h[j - i]) %= MOD;
    }
    for (int j = 1; j < i; ++j) {
      (gorf[j + i] += 2) %= MOD;
      (h[j + i] += 1) %= MOD;
    }
  }
  for (int i = 1; i <= T; ++i) {
    qw(frog[query[i]] * (mpow(mpow(2, query[i]), MODP)) % MOD, '\n', true);
  }
  return 0;
}

ll mpow(const ll x, int y) {
  ll _ret = 1, _tmp = x;
  while (y) {
    if (y & 1) (_ret *= _tmp) %= MOD;
    (_tmp *= _tmp) %= MOD;
    y >>= 1;
  }
  return _ret;
}

Guess you like

Origin www.cnblogs.com/yifusuyi/p/11789923.html