Skip to content

anson0221/Powerset.cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Generate-Powerset

• The power set of S is the set of all possible subsets of S.

• The amount of elements in S is less than or equal to 10.

宣告 vector S(10) 來存入input,再創一個容量為10的 vector X , 將其初始化為 {0,0,0,0,0,0,0,0,0,0} ,X.at(n) 對照到 S.at(n), 如果 X.at(n) 等於1則在這個 subset 中 S.at(n) 存在,若為零則不存在。 X一開始全為0,呼叫兩次 Combination() ,一次 X.at(0) 等於1,一次讓它等於0, 這兩次再各呼叫兩次 Combination() ,直到 X.at(n-1)(n = input 個數)時將結果對照S印出來, 最後可得2^n組 subset 生成。

--input--

wq s

a b c

cbg y e tq

--output--

{} {s} {wq } {wq s}

{} {c} {b } {b c} {a } {a c} {a b } {a b c}

{} {tq} {e } {e tq} {y } {y tq} {y e } {y e tq} {cbg } {cbg tq} {cbg e } {cbg e tq} {cbg y } {cbg y tq} {cbg y e } {cbg y e tq}

About

The power set of S is the set of all possible subsets of S.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages