题目大意:原题链接 锯木板,锯木板的长度就是花费.比如你要锯成长度为8 5 8的木板,最简单的方式是把21的木板割成13,8,花费21,再把13割成5,8,花费13,共计34,当然也可以先割成16,5的木板,花费21,再把16割两个8,花费16,总计37,现在就是问你花费最少的情况. 思路:转化为哈弗曼树 解法一:AC #include<cstdio> #include<algorithm> #define maxn 20010 using namespace std; int n…
Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 53645   Accepted: 17670 Description Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000)…
题目大意:原题链接 给你一个字符串,首先是计算出一个按正常编码的编码长度,其次是计算出一个用霍夫曼编码的编码长度,最后求正常编码的长度除以霍夫曼编码长度的比值,保留一位小数. 解题思路:需要知道 1.正常的编码长度的话,由于都是ASCII码值所以编码长度都为8,所以总长度就是8*字符串的长度Len就行. 2.哈弗曼树带权路径之和WPL=非叶子节点权值之和 刚开始一直不明白运行结果都正确了,为什么Compile Error,后来才知道原来iostream头文件不包含printf,所以又加上了cst…
Description Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needsN (1 ≤ N ≤ 20,000) planks of wood, each having some integer lengthLi (1 ≤ Li ≤ 50,000) units. He then purchases a sin…
题目:http://poj.org/problem?id=3253 没用long long wrong 了一次 #include <iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<stack> #include<queue> #include<iomanip> #include<cmath> #include<…
http://poj.org/problem?id=3253 这道题约等于合并果子,但是通过这道题能够看出来哈夫曼树是什么了. #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<queue> using namespace std; #define LL long long ; int n…
题目链接:http://poj.org/problem?id=3253 题目大意: 有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度 给定各个要求的小木板的长度,及小木板的个数n,求最小费用 以 3 5 8 5为例: 先从无限长的木板上锯下长度为 21 的木板,花费 21 再从长度为21的木板上锯下长度为5的木板,花费5 再从长度为16的木板上锯下长度为8的木板,花费8 总花费 = 21+5+8 =34 解题思路:哈夫曼编码模板 代码:…
poj 3253 Fence Repair 优先队列 Description Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) u…
POJ 3253 Fence Repair(修篱笆) Time Limit: 2000MS   Memory Limit: 65536K [Description] [题目描述] Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, eac…
POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needsN (1 ≤ N ≤ 20,000) planks of wood, each having some integer lengthLi (1 ≤ Li ≤ 50,000) units. He the…