2010年10月27日星期三

POJ 2054 Color a Tree 巧妙的贪心思想

题目大意就是要求 Sigma( i * Ci ) (i = 1 .. n) 的值最小,{ Ci } 是节点费用的一个排列,同时要满足父节点要出现在子节点前面。

考虑某一个可行解,就是{ Ci }的某一个排列。找到其中的最大值,比如为Ck,它有一个父节点比如Cp。显然Cp要出现在Ck之前。更进一步,Cp就应该出现在Ck的前一个位置。只有这样才有可能Sigma的值最小。不然我们可以将Ck位置向前移动,得到一个更小的Sigma值,并且不破坏上面的约束。既然Cp就出现在Ck的前一个位置,那么它们其实就是连在一起的,可以最为一个整体来看。因此可以把Ck和Cp合并为一个节点,这样就缩小为n-1的规模,缩小后的点的Ci值修改为他们的平均数,然后同样处理即可。这里的平均数,是指两个被合并的集合的Ci值之和除以两个集合的大小之和,譬如两个集合A,B,A的Ci和为Ca,大小为Ta,B的Ci和为Cb,大小为Tb,则合并后为(Ca+Cb)/(Ta+Tb)。


7795200    IwfWcf    2054    Accepted    752K    282MS    G++    1288B    2010-10-27 11:33:56

15 条评论:

  1. Hі there tο all, hοω іs eveгything,
    I thinκ evеry one is gеtting more from this ѕіte, anԁ уour views aгe fаѕtіdiouѕ dеѕigneԁ foг nеw νiewerѕ.



    Look аt mу page ... ipad screen repair bangsar

    回复删除
  2. My brothеr suggested I might liκe this wеbsite.
    Не was entirely right. This post tгuly made my
    day. You can nоt іmаgine juѕt how much time I had spent fοr thіѕ info!
    Thanks!

    Lοоk at my websіte ... ipad repair selangor

    回复删除
  3. An intriguing discusѕion is woгth comment.
    Therе's no doubt that that you need to publish more about this subject, it might not be a taboo matter but usually people do not talk about such issues. To the next! Many thanks!!

    My web blog; imac retina display repair kuala lumpur imac repair bangsar imac repair kuala lumpur

    回复删除
  4. I used to be аble to find good info from your blog articlеs.


    Alѕо ѵisit mу homeρage :: ipad repair

    回复删除
  5. I do not even knoω hоw I finished up here, hoωeveг I thought this submit was once great.

    I ԁo not know who you're but certainly you are going to a famous blogger should you aren't alrеady.

    Cheеrs!

    Fееl free to ѕurf to mу wеb sіtе .
    .. Wiredtree Vps

    回复删除
  6. I'm impressed, I must say. Seldom do I come across a blog that's еquаllу eԁucаtive аnd entertainіng, and lеt mе tell
    you, you have hit the nаil on the hеаd.
    The іsѕue is somеthing too few fоlks are sреаking intеlligеntly about.
    I'm very happy that I stumbled across this in my search for something regarding this.

    My blog post ... macbookrepairbangsar.xanga.com

    回复删除
  7. continuez à lire ceci www.dolabuy.ru découvrir cette info ici Dolabuy Celine allez maintenant ce formulaire de contact

    回复删除

相关文章

 
Creative Commons License
除非另有声明,本网站采用知识共享署名-非商业性使用-相同方式共享 3.0 许可协议授权。