摘要: Problem description:Please list all of the subsets of a known set including the empty set.Thinking: the subset's sum of a super set is(n is the number of the super set element) while an-bitbinary space could expressnumbers too.So our target is to generate all of the binary numbers in n bit space 阅读全文
posted @ 2013-01-04 16:34 NeilHappy 阅读(212) 评论(0) 推荐(0)
摘要: 问题描述:列出给定集合的所有子集合,包括空子集。 思路:一个集合的所有子集合的个数是个(n是集合中元素的个数),而一个位数为n的二进制也可以表示个数,所以,只要产生出了所有二进制数,就可以列出所有的子集了。在二进制的求解中,先来看这样一个例子。11111 01111+ 1--------------------11111 10000 当这个数加1时,如果当前位是1,那么当前位就变成0并且向前进1位;接着前一位如果是1,也会变成0并且继续进位;以此类推,直到遇到当前位是0的情况,就变成1,然后整个加法就完成了。依照此思路,很容易写出代码。 1 #in... 阅读全文
posted @ 2013-01-04 16:10 NeilHappy 阅读(402) 评论(0) 推荐(0)