Tree + backpack Regulation

Recently made a lot of good questions, write down the solution to a problem;
trees regulation + backpack topics:
Skilled pou points:
feeling or seniors method is better, the number of direct dp program, and finally multiply the probability, simple and effective;
the tree coloring:
beginning dp style are wrong (hereinafter error explanations)
{
taking into account each subtree, easy to think of
f [i] [j] [ 0/1] i represents a subtree rooted in, (i black / white sub) J th optimal value of sunspots;
D [I] [J] [0/1] [0/1] corresponding to the state of the subtree represents all black / white sub-root node to the distance;
later found to satisfy local optimum can not be satisfied global optimum. . .
}
So a direct contribution to the global consider each edge of;
dp own style yy what came out

the poor and supermarkets; relatively simple
attention to the scope of consolidation, n ^ 2 and n ^ 3 is only an idea;
you should first transfer the value of re-dp accumulating subtree size, otherwise,
according to the point, when a card is to chain n ^ 3 (the number of leaves to reach point n ^ 2)

the last question: sao;
title enough sao name; the subject is sao have a pi;
most people would just look at it as DAG (directed acyclic), I am the most people. . .
Later I found that both can be used as a tree, regardless of the direction when moving to;
F [i] [j] denotes the subtree to take into account the root of the root node i is ranked as number of program j;
recording and transfer prefix, plus some combination of intermediate number;
attached to a multi-pole semifinished bug;
IF (W [I] ==. 1) //
{
    for(int j=sz[g];j>=1;--j)
    {
        if(!tmp[po^1][j])continue;
        for(int k=1;k<=sz[to[i]];++k)
        {                    
            tmp[po][j+k]+=tmp[po^1][j]*(sum[to[i]][sz[to[i]]]-sum[to[i]][k])*C[j+k-1][k] *C[sz[to[i]]+sz[g]-j-k][sz[g]-j];
            tmp[po][j+k]%=mod;
        }
        tmp[po][j]+=tmp[po^1][j]*sum[to[i]][sz[to[i]]] *C[sz[to[i]]+sz[g]-j][sz[g]-j] ;
        tmp[po^1][j]=0;
    }
}

else
{
    for(int j=sz[g];j>=1;--j)
    {
        if(!tmp[po^1][j])continue;
        for(int k=1;k<=sz[to[i]];++k)
        {
            tmp [po] [j + k ] + = tmp [po ^ 1] [j] * sum [to [i]] [k] * C [j + k-1] [k] * C [sz [to [ I]] + SZ [G] -JK] [SZ [G] -j];    
            tmp [PO] [J + K]% = MOD;
        }
        tmp [PO ^. 1] [J] = 0;
    }
}
summary: the so-called tree gauge + backpack, a start point, thanks to the sub-tree together
(including the non-leaf nodes) to initialize all the points are the same;
therefore, the problem is converted to merge two sub-tree problem,
then we consider two sub-tree root nodes and edges of contribution or contribution cost or expense connected,
and then set the board backpack, pay attention to the transfer point to the number on it;

Guess you like

Origin www.cnblogs.com/loadingkkk/p/11220717.html