网站建设的通知网站维护分工,网站管理系统,网站如何做品牌营销,苏州官网网站首页https://vjudge.net/problem/UVA-10954 题意#xff1a;有n个数的集合S#xff0c;每次可以从S中删除两个数#xff0c;然后把它们的和放回集合#xff0c;直到剩下一个数。每次操作的开销等于删除的两个数之和#xff0c;求最小开销。 思路#xff1a;Huffman编码。 1 #…https://vjudge.net/problem/UVA-10954 题意有n个数的集合S每次可以从S中删除两个数然后把它们的和放回集合直到剩下一个数。每次操作的开销等于删除的两个数之和求最小开销。 思路Huffman编码。 1 #includeiostream 2 #includequeue3 using namespace std;4 5 struct cmp6 {7 bool operator()(const int a, const int b) const8 {9 return a b;
10 }
11 };
12
13 int main()
14 {
15 //freopen(D:\\txt.txt, r, stdin);
16 int n;
17 while (cin n n)
18 {
19 priority_queueint,vectorint,cmp q;
20 int ans 0, a;
21 for (int i 0; i n; i)
22 {
23 cin a;
24 q.push(a);
25 }
26 for (int i 0; i n - 1; i)
27 {
28 int b q.top(); q.pop();
29 int c q.top(); q.pop();
30 q.push(b c);
31 ans b c;
32 }
33 cout ans endl;
34 }
35 return 0;
36 } 转载于:https://www.cnblogs.com/zyb993963526/p/6357336.html