UVa 10954 Add All
发布时间
阅读量:
阅读量
题意:
给定一个包含n个元素的集合S,每次操作允许从集合中移除两个数值,并将它们的总和重新加入集合,持续进行该过程直至集合中仅剩一个元素。每次操作所需代价为所删除两个数值的总和,目标是求得所有操作代价的最小总和。所有数值均小于1e5。
分析:
这是否等同于构建哈夫曼树的过程?
代码:
#include<bits/stdc++.h>
#define LL long long
#define ms(s) memset(s, 0, sizeof(s))
using namespace std;
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
int n;
while(cin >> n && n) {
priority_queue<int, vector<int>, greater<int>> pq;
int x;
for(int i = 0; i < n; i++) {
cin >> x;
全部评论 (0)
还没有任何评论哟~
