随笔 - 62  文章 - 96  trackbacks - 0
<2007年7月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(7)

随笔分类(66)

随笔档案(62)

文章分类(31)

文章档案(32)

友情链接

最新随笔

积分与排名

  • 积分 - 231344
  • 排名 - 106

最新评论

阅读排行榜

评论排行榜

发现用stl中的bitset求子集树只要短短的几行代码
#include<iostream>
#include
<bitset>
using 
namespace std;
const int n = 4;
int main()
{
    
for(int i = 0; i < (1 << n); i++)
    {
        bitset
<n> bit(i);
        
for(int j = bit.size() - 1; j >= 0; j--)
            cout
<<bit[j];
        cout
<<endl;
    }
    
return 0;
}
n个元素有2^n个子集,
i从0到2^n - 1,
把它换算成二进制就分别对应一个子集。
posted on 2007-07-23 15:56 beyonlin 阅读(983) 评论(0)  编辑 收藏 引用 所属分类: C++之路

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理