Hrbust-1846
Test instructions: Sequence each lattice allows to put O and X, for a sequence of length n to hold at least m consecutive o of the scheme number
Rong +DP
Set \ (dp[i]\) is the number of legitimate scenarios when length is \ (i\)
The number of transfers comes from the previous state of the legal sequence followed by O and X, both \ (dp[i-1]*2\)
It may also come from the original illegal scheme, the transfer is legal, that first fixed a part of the state, because the transfer is legal, so assume that the sequence [i-m+1,i] all o, then the front can do whatever, there is \ (2^{i-m}\) state, but \ (2^ {i-m}\) there will be a legitimate scenario, so you need to subtract from the already valid \ (dp[i-m]\) scheme, and the remaining illegal scheme is followed by \ ([i-m+1,i]\) The total o number of scenarios. (However, this is not even a sample.)
YY a bit thought may be illegal program transfer is not the last one in the legal, and this has been included in the category of \ (dp[i-1]\) , so the latter part of the equation is crooked, then the \ ([i-m+1,i]\) is set to O, and \ ( i-m\) disposed of as X, indicating that it must be transferred to the last one in order to form a legitimate scheme, then the number of illegal schemes to be transferred is \ (2^{i-m-1}-dp[i-m-1]\)
Two parts plus it's okay.
https://paste.ubuntu.com/p/mYQPpgTb9N/
HDU-4370
Given \ (n*n\) matrix \ (c_{i,j}\), constructs a \ (n*n\) 01 matrix \ (x_{i,j}\)
\ (x_{i,j}\) satisfies the sum of the 1th row and is 1, the sum of the (n\) column and 1, the remainder of the \ (i\) line and the sum equal to the first \ (i\) column.
Make \ (\sum c_{i,j}*x_{i,j}\) the smallest
As a result of the spoiler, learned to convert to graph, node 1 out of 1, node n into the degree of 1, the remaining \ (1<i<n\) node into the degree is equal to the degree,\ (c_{i,j}\) is \ (i→j\) the weight value
The equivalence of the degrees and the degrees means that the non-starting point/end point or may have a ring, it is necessary to discuss whether 1 and n each form a ring, or just 1 to n simple path, compare weights can
https://paste.ubuntu.com/p/pY2gVmJxkf/
FZU-2234
Test instructions: Maximum value for double-tuning shortest circuit
The process can be seen as two people at the same time at the beginning to the end, but the goods can only be taken once, but the time can not withstand \ (O (n^4) \)
Because walking is the shortest way, for someone has gone \ (k\) length, you can get \ (x_i+y_i=k+2\)
So set \ (dp[k][x_i][y_i]\) for the length of the walk K when the first person in the horizontal axis \ (x_i\) and the second person in the horizontal axis \ (x_j\) the maximum value
If the coordinates are equal, the value of the two items is considered to be only taken once, except two.
https://paste.ubuntu.com/p/nssf9KynCF/
codeforces-337d
Test instructions: gives a tree of n points and a point of M markers, to find out how many points from the farthest mark point not more than D
Nice tree dp (good for Root)
The furthest distance from the mark Point ( f[i]\) to \ (i\) and \ (i\) subtree, if not present ( -\infin\)(guarantees the correctness of the subsequent addition)
The furthest distance from the mark point of \ ( g[i]\) to \ (i\) and \ (i\) subtree, or \ (-\infin\) If it does not exist.
So the answer is the number of \ (i\) of \ (max (f[i],g[i) ≤d\)
\ (f[i]\) very easy to engage, just \ (F[u]=max (f[u],f[v]+1) \)
\ (g[i]\) need to consider the father of \ (i\) and the brother of \ ( i\) ,\ (G[u]=max (g[u],g[fa]+1,f[v]+2) \)
Obviously each \ (u\) to Brother \ (v\) enumeration can be the Chrysanthemum Tree card fly
Then a simple optimization is required, logging for each node \ (fa\) record \ (f[]\) the largest son node \ (best[fa]=v\)
So for the enumeration to \ ( best\) node \ (u\) that is originally a father, the pair \ (g[u]\) needs to be violent to enumerate all the siblings, not the \ (best\) node . \ (G[u]=max (g[u],g[fa]+1,f[best[fa]]+2) \)
https://paste.ubuntu.com/p/9JcQYSjGHx/
codeforces-675e
Test instructions:\ (n\) stations, each station \ (i\) can spend 1 of the cost of arrival station \ ([i+1,a_i]\), set \ (p[i][j]\) for \ (i\) to \ (j\) minimum cost, beg \ (\sum_{1≤i , \ (n<10^6\)
The cost is the greedy DP under the fixed value
Set \ (dp[i]\) to \ (\sum_{i≤u<v≤n}p[u][v]\), then the answer is \ (\sum_{i=1}^{n-1}dp[i]\)
Consider how to transfer, the first thing you can know is the cost of \ (i→[i+1,a_i]\) is 1,\ (i→[a_{i+1},a_{i+2},..., a_{a_i}]\) cost 2, and so on
But \ ([a_{i+1},a_{a_i}]\) is non-monotonic, still need to maintain the maximum value so that each transfer as far as possible, so that the existence of the maximum value of the subscript is \ (m\)
The transfer equation is \ (dp[i]=dp[m]+[(n-i)-(a_i-m)]\)
yy a bit correctness, each transfer according to this greedy strategy, for each \ (i\) is certainly one of the fastest arrival \ ( n\) solution?
In fact, this question is not a DP, just a memory means
https://paste.ubuntu.com/p/xwHRv4SqSn/
Hrbust-1256
Test instructions: Give \ (n\) individual, request to set up \ (k\) detachment to iron, each detachment's fighting power for \ (a[i]+a[j]+a[k]+b[i][j]+b[i][k]+b[j][k]\), To seek the highest total combat power
Range \ (n<19\) pressure DP optimization
First \ (O (n^3*2^n) \) No, need pressure constant, referring to Dalao's speech, because the state is always 3 appear, and its violent three-layer enumeration, instead of k-1 times dine to update the answer, so the complexity is \ (O (can over) \)
https://paste.ubuntu.com/p/2wd72Ddg6B/
codeforces-611dhdu-6070
Test instructions: The minimum value of \ (\frac{cnt[l,r]}{r-l+1}\ ),\ (cnt[l,r]\) indicates the range \ ([l,r]\) of the value type
Fractional planning questions Consider the two answers \ (mid\), have \ (cnt[l,r]≤ (r-l+1) *mid\), the number of times need to maintain the relationship between the type number and length, bad check
Bashi to \ (cnt[l,r]+ (L-1) *mid≤r*mid\), each check enumerates the right endpoint, the left side with the line tree to update the answer, each time inserting a new R update will only affect the value of CNT, as long as the record of each type of the previous value where can be, maintains a dynamic suffix
(feeling that your counting ability is too weak)
https://paste.ubuntu.com/p/dtDGK6YPJT/
codeforces-817d
Test instructions: (\sum max (a[l,r))-\sum min (a[l,r]) \)
Loved the monotonous stack
First, the smallest part,
For each \ (i\), it can extend to the left-wing boundary of \ (l[i]\), making \ (a[j]>a[i],j∈[l[i],i-1]\), and corresponding to finding the right-wing boundary \ (r[i]\) , making \ (a[j]≥a[i],j∈[i,r[i]]\)
At this time \ (i\) The contribution of the answer is \ ((i-l[i]+1) * (r[i]-i+1) \), note that the number of intervals containing \ (i\) should be both sides have \ (i\) intersection!
Similarly, maintain the largest portion for each \ (i\),\ (a[j]<a[i],j∈[l[i],i-1]\), and \ (a[j]≤a[i],j∈[i,r[i]]\)
https://paste.ubuntu.com/p/kY2Ws2bfG6/
codeforces-478d
Test instructions: R red squares and G green squares, require the i\ \ ( i\) of the same color squares, to find out the total number of options
Garbage problem, wasting time
\ (dp[i][j]\): the \ ( i\) layer uses a \ (j\) Red Square scheme number, and then respectively with red squares and green squares to transfer, pay attention to the details
In particular, the break judgment of sum should not be placed at the bottom of the while, because so H may be just the missing layer
https://paste.ubuntu.com/p/jQJxsVmHcB/
codeforces-366c
Test instructions: Give \ (a[1...n],b[1...n]\), beg \ (\frac{\sum a[i]}{\sum b[i]}=k\) and \ (\sum a[i]\) as large as possible the collection scheme, output \ (\sum a[i]\)
Backpack with a total cost of 0
Because it is a collection, each element can only be taken once, and requires the value and maximum, in accordance with the 01 backpack background
Bashi expansion to \ (\sum a[i]-\sum k*b[i]=0\), you can see the volume of \ (a[i]-k*b[i]\), the value of \ (a[i]\)
Run it over again. 01 Backpack is OK, target is \ (dp[n][0]\)
Trying to make a death unordered_map
https://paste.ubuntu.com/p/BkyMYqxzPJ/
codeforces-466dhdu-2833hdu-5242codeforces-489f
Test instructions: The former M-line 01 matrix is known, and the 01 matrix for construction \ (n*n\) makes each row only 2 1 of the scheme number
\ (dp[i][j][k]\): The total number of columns for the current \ (i\) line is \ (j\), and the total number of columns and 1 is \ (k\)
Since each line is required to be 2 1, that is, the transfer process of the new construction line must be filled in 2 1, this is a breach
\ (dp[i][j][k]=dp[i-1][j+2][k-2]* {j+2 \choose 2} + dp[i-1][j+1][k]* (j+1) * (k) +dp[i-1][j][k+2]*{k+2\choose 2}\)
Target is \ (dp[n][0][0]\)
But this will T
One workaround is to enumerate \ (i\) rows and \ (j\) locations, which can be computed by \ (k= (n-i+1) *2-j*2\)
https://paste.ubuntu.com/p/rjNc844Hcj/
hdu-2853hdu-4360ural-2080
Viewing title: cf669d/51nod-1021/hdu4101/
OJ hung up: CSU1809
Recycle Bin: hdu4472/cf550c/cf660c/cf353d/hrbust1774/cf430d
Map Related: cf821d (view the ranks as points)
[Collection] National Day Leisure supplementary Questions