POJ - 3253 Fence Repair
来源:互联网 发布:淘宝分享送红包 编辑:程序博客网 时间:2024/05/17 07:49
题意:要将一个木板分成几个小的木板,每次的费用是当前木板的大小,求得到所有木板的最小花费
思路:利用Huffman思想,采用优先队列
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;struct node{ long long len; bool operator<(const node &a)const{ return len > a.len; }};priority_queue<node> s;int main(){ int n; node a; scanf("%d",&n); for (int i = 0; i < n; i++){ scanf("%lld",&a.len); s.push(a); } long long ans = 0; while (s.size() > 1){ node x = s.top();s.pop(); node y = s.top();s.pop(); x.len += y.len; ans += x.len; s.push(x); } printf("%lld\n",ans); return 0;}
0 0
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253Fence Repair
- POJ--3253 -- Fence Repair
- poj-3253-Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- poj 3253 Fence Repair
- POJ - 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- poj 3253---Fence Repair
- 杭电OJ 1159 :Common Subsequence
- Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)
- 杂谈
- 随笔
- LeetCode Reverse Linked List II
- POJ - 3253 Fence Repair
- 去名字前的空格
- mysql的左右内连接
- mysql-5.5源码编译安装(附参数对照表)
- LeetCode 148 — Sort List(C++ Java Python)
- mysql数据库的安装
- Java容器类List、ArrayList、Vector及map、HashTable、HashMap的区别与用法
- 胖子伤不起
- XML与HTML的区别