摘要:
题意:最多去掉一个树上的s条边,将树分割成S+1块,使得所有块的最长链的最大值最小.USACO官方的题解讲的很清楚..First, conduct a binary search on the answer, D. To do this, just find a way to check, for any D, if it is possible to make S cuts such that each tree has diameter at most D.We will give a greedy algorithm which will compute the smallest num 阅读全文
摘要:
简单的最短路.要用堆优化的dijkstra.当复习了.code:/************************************************************** Problem: 2100 User: exponent Language: Pascal Result: Accepted Time:572 ms Memory:7356 kb ****************************************************************/ type edge=record v,w,n:longint; end; const maxm= 阅读全文
摘要:
首先O(N^2)的DP挺好想的.f[i,j]=sum[i,j]-min(f[i+1,j],f[i,j-1]).但题目把n出到5000,内存卡到64M,二维的状态存不下..其实,j这一维可以省掉.我们换个状态表示f[i,i+len]=sum[i,i+len]-min(f[i+1,i+len],f[i,i+len-1])然后循环这样写:for len=1 to n for i=1 to n-len.容易看出第二维可以省掉了.code:/************************************************************** Problem: 2101 User: 阅读全文
摘要:
简单的LCA.有一个结论,每个party中最远的点对中,必有一个点是该party中深度最大的点.然后记low[i]为第i个party的最深点,对每一个点查询dist(i,low[belong[i]]).belong就是第i个点属于哪个party.对于树上两点,dist(u,v)=depth(u)+depth(v)-2*depth(lca(u,v)).一开时用RMQ的LCA死活过不去.无奈,只好去学了tarjan的LCA.code:/************************************************************** Problem: 1776 User: 阅读全文