Copyright© 2004 Sergiu Dumitriu, Marta Gî rdea, Că tă lin Hriţ cu Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License" All brand names, product names, or trademarks belong to their respective holders.
標(biāo)簽:
Permission
Copyright
259
Dumitriu
上傳時(shí)間:
2015-04-02
上傳用戶:jackgao
Ex4-22 單射函數(shù)問(wèn)題
« 問(wèn)題描述:
設(shè)函數(shù)f將點(diǎn)集S = {0,1, , n -1}映射為f (S) = { f (i) | iî S} Í S 。單射函數(shù)問(wèn)題要
從S中選取最大子集X Í S 使f (X )是單射函數(shù)。
例如,當(dāng)n=7, f (S) = {1,0,0,2,2,3,6} Í S 時(shí), X = {0,1,6} Í S 是所求的最大子集。
« 編程任務(wù):
對(duì)于給定的點(diǎn)集S = {0,1, , n -1}上函數(shù)f,試用抽象數(shù)據(jù)類型隊(duì)列,設(shè)計(jì)一個(gè)O(n)時(shí)
間算法,計(jì)算f的最大單射子集。
« 數(shù)據(jù)輸入:
由文件input.txt 提供輸入數(shù)據(jù)。文件的第1 行有1 個(gè)正整數(shù)n,表示給定的點(diǎn)集
S = {0,1, , n -1}。第2 行是f (i)的值,0 £ i < n。
« 結(jié)果輸出:
程序運(yùn)行結(jié)束時(shí),將計(jì)算出的f的最大單射子集的大小輸出到output.txt中。
輸入文件示例 輸出文件示例
input.txt
7
1 0 0 2 2 3 6
output.txt
3
標(biāo)簽:
Iacute
61516
laquo
icirc
上傳時(shí)間:
2016-05-28
上傳用戶:tyler