poj Fence Repair 贪心
来源:互联网 发布:知乎大学排名 编辑:程序博客网 时间:2024/05/17 06:51
反过来做,就是要合成一个板,容易想到每次选取最小的两块合并,结果最优。
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#define ll long longusing namespace std;const int maxn=2e4+9;int main(){ int n; priority_queue <ll,vector<ll>,greater<ll> > q; while(scanf("%d",&n)!=EOF) { while(!q.empty()) q.pop(); for(int i=1,tmp;i<=n;i++) { scanf("%d",&tmp); q.push(tmp); } long long ans=0; for(int i=1;i<n;i++) { long long tmp=0; tmp+=q.top(),q.pop(); tmp+=q.top(),q.pop(); ans+=tmp; q.push(tmp); } cout<<ans<<endl; } return 0;}
- poj Fence Repair 贪心
- POJ 3253 Fence Repair(贪心)
- poj 3253 Fence Repair 贪心
- POJ 3253 Fence Repair 贪心
- Poj 3253 Fence Repair【贪心】
- POJ 3253 Fence Repair(贪心)
- 贪心法-Fence Repair POJ
- POJ 3253 Fence Repair (贪心&优先队列)
- POJ 3253 - Fence Repair(贪心)
- POJ 3253 Fence Repair(贪心,优先队列)
- POJ 3253 fence repair 贪心法 huffman
- POJ 3253 Fence Repair(贪心+优先队列)
- POJ 3253 Fence Repair(经典贪心问题)
- POJ 3253 Fence Repair 贪心+优先队列
- POJ 3253-Fence Repair(贪心)
- POJ 3253 - Fence Repair(贪心+Huffman)
- poj 3253 Fence Repair 【huffman树 贪心】
- POJ 3253 Fence Repair(贪心, Huffman编码)
- fork
- cygwin的用户设置
- 一个MATLAB 写xml 文件的例子
- 聚集索引和非聚集索引
- 如何搜索codeforces的解题代码
- poj Fence Repair 贪心
- Windows下模拟Linux 的 time命令,实测PHP 5.3 5.4 5.5的速度比较
- hello world
- hdu - 4601 - Letter Tree(bfs+dfs+Trip+二分+RMQ)
- ACMICPC 2013 长沙 F 题Curve in Circle
- Android逆向分析必备网址大全
- cc1plus: warnings being treated as errors
- CocoaPods 安装 及 简单的应用
- android工具集-android安全