huffman完整源代碼C語言實現,有本人超級詳細解釋(看不懂你去跳樓吧)
算法設計:
1、對給定的n個權值{W1,W2,W3,...,Wi,...,Wn}構成n棵二叉樹的初始集合F={T1,T2,T3,...,Ti,...,Tn},其中每棵二叉樹Ti中只有一個權值為Wi的根結點,它的左右子樹均為空。(為方便在計算機上實現算法,一般還要求以Ti的權值Wi的升序排列。)
2、在F中選取兩棵根結點權值最小的樹作為新構造的二叉樹的左右子樹,新二叉樹的根結點的權值為其左右子樹的根結點的權值之和。
3、從F中刪除這兩棵樹,并把這棵新的二叉樹同樣以升序排列加入到集合F中。
4、重復二和三兩步,直到集合F中只有一棵二叉樹為止。
標簽:
huffman
C語言
源代碼
上傳時間:
2013-12-29
上傳用戶:ouyangtongze
The government of a small but important country has decided that the alphabet needs to be streamlined and reordered. Uppercase letters will be eliminated. They will issue a royal decree in the form of a String of B and A characters. The first character in the decree specifies whether a must come ( B )Before b in the new alphabet or ( A )After b . The second character determines the relative placement of b and c , etc. So, for example, "BAA" means that a must come Before b , b must come After c , and c must come After d .
Any letters beyond these requirements are to be excluded, so if the decree specifies k comparisons then the new alphabet will contain the first k+1 lowercase letters of the current alphabet.
Create a class Alphabet that contains the method choices that takes the decree as input and returns the number of possible new alphabets that conform to the decree. If more than 1,000,000,000 are possible, return -1.
Definition
標簽:
government
streamline
important
alphabet
上傳時間:
2015-06-09
上傳用戶:weixiao99