这是一棵普通的二叉哈夫曼树。
#include<iostream>
#include<queue>
using namespace std;int main()
{int N;while( scanf("%d",&N)!=EOF ){priority_queue< int,vector<int>,greater<int> > PQ;int len;__int64 ans=0;for( int i=0;i<N;i++ ){scanf( "%d",&len );PQ.push(len);}int sum=0;while( PQ.size()!=1 ){sum=PQ.top();PQ.pop();sum+=PQ.top();PQ.pop();PQ.push(sum);ans+=sum;}//ans+=PQ.top();printf( "%I64d\n",ans );}return 0;
}