正能量的dp——状压/容斥
Summary
Tolerance and reprimand
Title
P6846
The first thing I found was that if you reverse all the edges of a DAG, it is still a DAG. And the sum of these two edges is \(m\). So the answer is \(m\) multiplied by the number of directional DAG schemes divided by two.
Consider the characteristics of a DAG and consider splitting it into several layers with a degree of \(0\). This inspired us to consider a count where \(f_{S}\) means that \(S\) is the number of DAGs, and the transfer finds a layer, which requires that the layer is obviously an independent set. So
It is found that this obviously counts as heavy, because there may be a \(0\) entry point in \(S\setminus T\), so if \(F(A)\) means that the imperial \(A\) is the calculated coefficient of the independent set, i.e. \(f_{S\setminus A}2^{E_{A\to S\setminus A}}\), \(G(A)\) means that the independent set happens to be the number of schemes of \(A\), so there is
This is equivalent to simply multiplying the original formula by \((-1)^{| T|+1}\) of the coefficient. Or intuitive understanding is the principle of tolerance and repulsion. \(A\cup B=A+B-A\cap B\)。 So the time complexity is \(O(3^n)\).
A
First of all, if the original graph is not an SCC, then the shrinkage point is followed by a DAG. So this question is very similar to the previous one.
Let \(f_{S}\) indicate that \(S\) is not the number of strong connectivity solutions, which is equivalent to the DAG after shrinking. So just like the previous question, enumerate a set, because you don't know how many independent sets it has after shrinking, so set \(g_{S,i}\) to represent the number of \(i\) independent sets after the \(S\) shrink, then there are similar to the previous question
where \(2^{E\setminus T}\) is because the edges in this set can be randomly connected without guaranteeing a DAG, because \(S\) must not be an SCC.
Then this transfer is a bit problematic, when \(T=S\) is counted \(g_{T,1}\) more, and this is equivalent to \(S\) is an SCC, so it can't be counted. And \(g_{S,1}=2^{E_S}-f_S\), you need to calculate \(f_S\) to find it, so it avoids the situation of self-transfer. \(g_{S,i\ge 2}\) is easy to find.
Then the time complexity is \(O(3^nn)\), but I noticed that the \((-1)^{i+1}\) coefficient can be directly recorded as \(g_{T}\), so I finished it.
\(\color{red}-\) is a coefficient of \(-1\).
E
The answer obviously won't be more than \(n\). Consider how to use operation 2 to save the number of times. It is easy to see that there must be several collections \(S\) using \(| S|-1\) operation binary becomes full \(0\), because if \(\ge | S|\) is not as good as using the all-purpose operation \(1\),\(<| S|-1\) can definitely continue to be dismantled. Then the remaining number uses the operation to become \(0\).
To make the answer minimal, i.e. make such \(S\) the most. Considering that the two numbers of operation 2 are connected to characterize the operation, then according to the above conclusion, \(S\) must be optimal when the tree is the best. Consider what kind of \(S\) is legitimate.
Consider the weakening problem first, choose two numbers \(-x\) each time, and randomly designate a point as the root of the tree, then consider peeling leaves, only need the weight of the final root to be \(0\). It is found that the contribution of the odd layer to the root is \(+\), and the contribution of the even layer is \(-\), so the weight of the odd layer and the equal sum of the weights of the even layer are the legal sufficient conditions for \(S\). Further, this is equivalent to finding a subset of \(T\), so that the sum of the weights of \(T\) is equal to the sum of the weights of \(S\setminus T\), because it is bound to be reduced to a tree.
Now becomes a \(-x\) a \(-x-1\). This is equivalent to executing \(| on top of the previous level S-1|\) operation, each time the weight of the odd or even layer is \(+1\), and then the final weight is equal. The formalized is to find the subset \(T\) so that \(|s(T)-s(S\setminus T)|\le | S|-1\) and \(|s(T)-s(S\setminus T)|\equiv | S|-1\pmod 2\), because changing it once will change \(2\). That is, \(s(S)\equiv | S|-1\pmod 2\)。
Then the legal time complexity is $2^{| S|} $, for all \(S\) is \(3^n\), the constant is a bit too considered. The more classic one is to fold it in half, and after sorting the two sides, you can scan it with double pointers, the problem is sorting, it is $O(\sqrt 2^{| S|}| S|) $ , and then found that considering adding a number to the set each time, it can be merged and sorted, so I removed \(| S|\), the total time complexity is \(\displaystyle\sum_{i=0}^{n}\binom{n}{i}\sqrt 2^i=(\sqrt 2+1)^n\).
Then it's basically done, just do the \((\max,+)\) subset convolution to calculate the maximum amount of \(S\), which is a constant small \(3^n\), so it can pass. Of course, it can also be multiplied + subset convolution to achieve \(O(2^nn^2\log n)\), which is not very meaningful.
Tips:
- Subset halving.
- Binary consideration mapping.
C
First of all, the answer is obviously not to exceed the value range. Then analyze it, if you have determined the set of responding audiences, then the optimal strategy must be to replace the maximum number of \(\le a_i\) in the current \(B\) with \(a_i\), and add a new element if it does not exist. Or you can use Dilworth to turn the original problem into the least divided non-descending subsequence.
Found that the elements in \(B\) must be different from each other. Therefore, a dp can be designed, \(f_{S,i}\) represents the current \(B\) element composition set is \(S\), considering the first \(i\) and determining whether the audience response of the \(i\) is feasible, so that \(O(2^Vn)\) can be achieved.
\(f_{S,i}\) is only \(0,1\), so considering the swap state and domain, in fact, the final answer only cares about what \(f_{S,n/n-1}=1\), so we only need to focus on the farthest \(i\) that \(S\) can reach. Let's set \(g_{S}=\max\limits_{f_{S,i}=1}i\).
Then it is found that the transfer has a self-loop, that is, if the current \(g_S=p\), if it is \(a_{p+1}\in S\), then it can continue to expand; Otherwise, if \(a_{p+2}\in S\), it can continue to expand. Because the new \(S'\) is equal to \(S\). So just find the smallest \(a_i, a_{i+1}\not \in S\)$i, you can do it by some method \(O(2^VV^2+nV)\), but that's not the point.
F
Considering that for a selected set of \(S\), assuming that the legal maximum length of only \(S\) can be \(f_S\), then obviously its legal length is \(\left[\sum_{i\in S}a_i, f_S\right]\) can be adjusted. So you only need to ask for \(f_S\) to find the answer.
$T If we directly set the state \(f_S\) to indicate that the selected number is \(S\) and the number that cannot be selected is \(\complement_U S\), we find that assuming that we currently want to select \(i\in S\), it is equivalent to \(S\) and is divided into two parts, namely \(S_1\) on the left and \(S_2\) on the right side of \(i\). It is found that \(S_1\) only requires that \(\complement_U S\) instead of \(\complement_U S_1\) cannot be selected during the selection process, so this approach is problematic.
Therefore, it is necessary to remember that \(f_{i,S,T}\) means that you want to choose the number in \(S\), and you cannot choose the longest length occupied by the number in \(T\), and the number currently considered is \(a_i\), consider it according to the situation
- \(i\in T\), then \(f_{i,S,T}=\min(a_i-\epsilon,f_{i+1,S,T})\), this is because \(i\) needs to be put first, and if the length \(\ge a_i\) is not legal.
- \(i\in S\), then \(f_{i,S,T}=a_i+\displaystyle\max_{S_1\cup S_2=S\setminus \{i\}}\left\{f_{i+1,S_1,T}+f_{i+1,S_2,T}\right\}\).
- Otherwise, don't worry, \(f_{i,S,T}=f_{i+1,S,T}\).
Considering the \(\epsilon\) question, I noticed that the final answer must be a closed and right-opening interval, so there is no need to care, just let \(f_S>m\) at the end.

浙公网安备 33010602011771号