<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>题解 on 红石的个人博客</title><link>https://qwqdhs.com/tags/%E9%A2%98%E8%A7%A3/</link><description>Recent content from 红石的个人博客</description><generator>Hugo</generator><language>zh-cn</language><managingEditor>qwqdhs@outlook.com (qwq的红石/屿寻sama)</managingEditor><webMaster>qwqdhs@outlook.com (qwq的红石/屿寻sama)</webMaster><copyright>本博客所有文章除特别声明外，均采用 BY-NC-SA 许可协议。转载请注明出处！</copyright><lastBuildDate>Wed, 04 Nov 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://qwqdhs.com/tags/%E9%A2%98%E8%A7%A3/index.xml" rel="self" type="application/rss+xml"/><item><title>P1090 [NOIP 2004 提高组] 合并果子 - 题解</title><link>https://qwqdhs.com/posts/p1090/</link><pubDate>Wed, 04 Nov 2026 00:00:00 +0000</pubDate><author>qwqdhs@outlook.com (qwq的红石/屿寻sama)</author><guid>https://qwqdhs.com/posts/p1090/</guid><description>
<![CDATA[<h1>P1090 [NOIP 2004 提高组] 合并果子 - 题解</h1><p>作者：qwq的红石/屿寻sama（qwqdhs@outlook.com）</p>
        
          <h1 id="原题链接洛谷">
<a class="header-anchor" href="#%e5%8e%9f%e9%a2%98%e9%93%be%e6%8e%a5%e6%b4%9b%e8%b0%b7"></a>
原题链接(洛谷)
</h1><p><a href="https://www.luogu.com.cn/problem/P1090">点我</a></p>
<h1 id="题目">
<a class="header-anchor" href="#%e9%a2%98%e7%9b%ae"></a>
题目
</h1><h2 id="题目背景">
<a class="header-anchor" href="#%e9%a2%98%e7%9b%ae%e8%83%8c%e6%99%af"></a>
题目背景
</h2><p><a href="https://www.luogu.com.cn/problem/P6033">P6033</a> 为本题加强版。</p>
<h2 id="题目描述">
<a class="header-anchor" href="#%e9%a2%98%e7%9b%ae%e6%8f%8f%e8%bf%b0"></a>
题目描述
</h2><p>在一个果园里，多多已经将所有的果子打了下来，而且按果子的不同种类分成了不同的堆。多多决定把所有的果子合成一堆。</p>
<p>每一次合并，多多可以把两堆果子合并到一起，消耗的体力等于两堆果子的重量之和。可以看出，所有的果子经过 $n-1$ 次合并之后， 就只剩下一堆了。多多在合并果子时总共消耗的体力等于每次合并所耗体力之和。</p>
<p>因为还要花大力气把这些果子搬回家，所以多多在合并果子时要尽可能地节省体力。假定每个果子重量都为 $1$，并且已知果子的种类数和每种果子的数目，你的任务是设计出合并的次序方案，使多多耗费的体力最少，并输出这个最小的体力耗费值。</p>
<p>例如有 $3$ 种果子，数目依次为 $1$，$2$，$9$。可以先将 $1$、$2$ 堆合并，新堆数目为 $3$，耗费体力为 $3$ 。接着，将新堆与原先的第三堆合并，又得到新的堆，数目为 $12$，耗费体力为 $12$。所以多多总共耗费体力 $=3+12=15$。可以证明 $15$ 为最小的体力耗费值。</p>
<h2 id="输入格式">
<a class="header-anchor" href="#%e8%be%93%e5%85%a5%e6%a0%bc%e5%bc%8f"></a>
输入格式
</h2><p>共两行。</p>
<p>第一行是一个整数 $n(1\leq n\leq 10^4)$，表示果子的种类数。</p>
<p>第二行包含 $n$ 个整数，用空格分隔，第 $i$ 个整数 $a_i(1\leq a_i\leq 2\times 10^4)$ 是第 $i$ 种果子的数目。</p>
<h2 id="输出格式">
<a class="header-anchor" href="#%e8%be%93%e5%87%ba%e6%a0%bc%e5%bc%8f"></a>
输出格式
</h2><p>一个整数，也就是最小的体力耗费值。输入数据保证这个值小于 $2^{31}$。</p>
<h2 id="输入输出样例-1">
<a class="header-anchor" href="#%e8%be%93%e5%85%a5%e8%be%93%e5%87%ba%e6%a0%b7%e4%be%8b-1"></a>
输入输出样例 #1
</h2><h3 id="输入-1">
<a class="header-anchor" href="#%e8%be%93%e5%85%a5-1"></a>
输入 #1
</h3><pre tabindex="0"><code>3 
1 2 9 
</code></pre><h3 id="输出-1">
<a class="header-anchor" href="#%e8%be%93%e5%87%ba-1"></a>
输出 #1
</h3><pre tabindex="0"><code>15
</code></pre><h2 id="说明提示">
<a class="header-anchor" href="#%e8%af%b4%e6%98%8e%e6%8f%90%e7%a4%ba"></a>
说明/提示
</h2><p>对于 $30%$ 的数据，保证有 $n \le 10^3$；</p>
        
        <hr><p>本文2026-11-04首发于<a href='https://qwqdhs.com/'>红石的个人博客</a>，最后修改于2026-11-04</p>]]></description><category>题解</category></item></channel></rss>