Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
poj 50题纪念附官方解题报告终于50题,继续努力 Consider the partial sum sequence of each of the k features built by taking the sum of all the values up to position i. The problem is equivalent to: Given an array s[n][k], find i,j, with the biggest separation for which s[ i ] [l]-s[j][l] is constant for all l. The problem is now to do this efficiently. Notice that s[ i ][l]-s[j][l] being constant for all l is equivalent to s[ i ][l]-s[j][l]=s[ i ][1]-s[j][1] for all l, which can be rearranged to become s[ i ][l]-s[ i ][1]=s[j][l]-s[j][1] for all l. Therefore, we can construct another array a[n][k] where a[ i ][j]=s[ i ][j]- s[ i ][1] and the goal is to find i and j with the biggest separation for which a[ i ][l]=a[j][l] for all l. This can be done by sorting all the a[ i ] entries, which takes O(nklogn) time (although in practice rarely will all k elements be compared). Another alternative is to go by hashing, giving an O(nk) solution. Both solutions are fairly straightforward once the final array is constructed. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator