哈夫曼编码问题…
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
priority_queue<int,vector<int>,greater<int> > que;
for(int i=0;i<n;i++)
{
int x;
scanf("%d",&x);
que.push(x);
}
int ans = 0;
while(que.size() != 1)
{
int x1 = que.top();que.pop();
int x2 = que.top();que.pop();
ans += x1+x2;
que.push(x1+x2);
}
cout<<ans;
return 0;
}