Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

雁过留声——状态压缩树形dp

Posted by fanhqme at 2009-07-15 10:26:17 on Problem 3719 and last updated at 2009-07-18 22:18:49
一看这道题就知道算法:
设f(i,j)为第i个节点用的weights的状态为j时的最小距离。

f(i,j)=min{k∈j,popcount(k)=leafcount(left)|f(left,k)+f(right,k^j)+abs(weight(k)/weight(j)-0.5)*1000}

但粗粗一算,状态数有6553600个,每个状态转移最多要用65536下
是铁定超时的。
本来想放弃,但重新计算一遍发现,状态其实最多2031616个
而每个状态转移所用的时间都是不同的,平均下来是一个不大的数
(原谅我,我的数学不好,但直觉告诉我这个数不大,最坏的情况出现在他几乎退化成链的时候)
所以,用这种方法就可以ac了!

不知道让N<=100的用意是什么,既然M<=16,N的个数不应该超过31个


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator