First, multiply all heights by 10, set f[i] to the minimum height for placing the first I book in the Bookshelf, then\[\begin{eqnarray*}F[i]=\min (F[j-1]+first (j,i) +second (j,i) +w-(s[i]-s[j-1]) \ \=\min (F[j-1]+first (j,i) +second (j,i) +w-s[i]+s[j-1]) \ \=\min (F[j-1]+first (j,i) +second (j,i) +s[j-1]) +w-s[i]\end{eqnarray*}\]Among them $1\leq J\leq i$ and $s[i]-s[j-1]\leq w$.Set Tmp[i][j]=f[j-1]+s[j-1]+first (j,i) +second (j,i), consider using a line segment tree to maintain TMP[I][J], if y
a previously available program.SolutionAt first glance is a network flow of the problem, but the actual completion will find the timeout over to Grandma's home. Theorem: The maximum flow of the plane graph = the shortest circuit of the graph's dual graph, an image explanation see a thoughtful god Ben after SPFA disorderly get Dijkstra, but I built side of the way a bit of ghost animal.1#include 2#include 3 using namespacestd;4 structnode5 {6 intV, W;7}edge[6000005];8 intfst[2000005],
the priority queue of data too much caused by the memory exceeded the limit, so hurriedly added a limit. Sure enough, it's over. Here is a Boolean array trainofpath[v] recorded to the V point of this side is not a railroad. If the road was originally a railroad, it is now the road that is updated, only to be updated; If you want to get a MLE code, if you are working on a highway that is currently being updated, some per
Give a direction graph, find the largest node set, any two points u,v. U can reach V or V to reach U.A strongly connected component must be selected together. So first find out all the SCC, and then pinch to run the DP on the DAG later.Note 0,0 This set of data#include using namespacestd;Const intMAXN =1005, MAXM = 5e5+1;intHEAD[MAXN],TO[MAXM],NXT[MAXM];voidAddedge (intUintVinti) {To[i]=v; Nxt[i]=Head[u]; H
Using Tarjan to find strong connected components, a DAG is formed after a strong connected component point has an equivalent contraction point, and a number of points a with a degree of 0 are calculated.With a size of 0 B, take one of them. A case in which the number of strongly connected components is 1.It's easier to read the Tarjan algorithm later.#include using namespacestd;Const intMAXN = 2e4+5;Const intMAXM = 5e4+5;inthead[maxn],nxt[maxm],to[max
ExercisesTree-shaped dp+ backpackDP[I][J] Indicates that I is the root, preserving the minimum number of edges required to be deleted by J nodesThe default 1 is the root. At the end of the calculation, 1 of the root of the tree should be added 1 (Cut off the Father node)Be aware of initializing .....Code:#include #include#include#includeusing namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineCLR (x) memset (x,0,sizeof x)#defineMC (x, y) m
vertex is the in point, and the bottom-right corner is the out point (network flow splitting idea).Build edge to find the shortest possible.By the way, the two types of Dijkstra have been tested, and this version, which is not commented out, is about 200ms slower than the commented version, and it seems that the inq judgment of the large constant is more time consuming than the high-constant priority queue.1 /*by Silvern*/2#include 3#include 4#include 5#include 6#include 7#include 8#include 9 u
son a father, and the father becoming a son, the conclusion is exactly the same, but the number of child nodes has changed.But d[i]=2* (N-siz[i])-1, and finally the read-in edge processing, each jump to the position of V to continueAnd then you'll find that the decimal is feint 23333Code#include using namespacestd;#defineN 100010#definell Long Longintt,n,m,q,cnt;intdep[n],f[n][ -],first[n];ll Up[n],down[n],siz[n];structemail{intu,v; intNXT;} E[n*4];inlinevoidAddintUintv) {e[++cnt].
attached to two cut points, one can not be from another to the other), the answer is tired by the conditions of the Unicom block points. ↑ input Data read in is the number of sides, silly as a point, read into the wrong, but also always check the problem of the algorithm ... ↑wa to fly after the anger to see the key, code to change and Tunix the basic same, only to find read into ... (Hope Day)1 /*by Silvern*/2#include 3#include 4#include 5#include 6#include 7#include 8 #defineLL unsigned long
The idea is actually very good to think: is backwards maintenance and check set.However? The details are super-large.First, each node can be attacked multiple times, just the one that started the attack.Second, consider the dependencies of a clear and checked set.#include #include #include #define Maxe 950050#define MAXV 950050using namespace Std;struct Edge{int v,nxt;}e[maxe];int G[MAXV],N,M,K,X,Y,NOW[MAXV],ANS[MAXV],CNT=0,NUME=0,FATHER[MAXV],FIRST[M
Ah, this is a code editor. I just found out today.Chain water problem. Maintains the color of the interval left and right endpoints.#include #include#include#include#defineMAXV 200500#defineMaxe 200500#defineMAXN 805000using namespacestd;intn,m,num[maxv],x,y,root=1, nume=0, tot=0, cnt=0, G[MAXV];intDIS[MAXV],TOP[MAXV],FATH[MAXV],SIZE[MAXV],SON[MAXV],W[MAXV],FW[MAXV];intLS[MAXN],RS[MAXN],LPOS[MAXN],RPOS[MAXN],LAZY[MAXN],SUM[MAXN];inta,b,c;BOOLVIS[MAXV],FFF[MAXV];Chartype[5];structedge{intV,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.