[Algorithm] Powerset Problem
By given an array [1,2,3]:
Return all possible combinations. for example: [[], [1], [2], [3], [1, 2].... [1,2,3]]
function combination(ary) {
let result = new Set();
function helper(ary, idx, path = [], result) {
if (idx === ary.length) {
return result.add(path);
}
let path_inc_current = [...path, ary[idx]];
let path_not_inc_current = [...path];
helper(ary, idx + , path_inc_current, result);
helper(ary, idx + , path_not_inc_current, result);
}
helper(ary, , [], result);
return Array.from(result);
}
console.log(JSON.stringify(combination([, , ]))); // [[1,2,3],[1,2],[1,3],[1],[2,3],[2],[3],[]]
[Algorithm] Powerset Problem的更多相关文章
- UESTC_Eight Puzzle 2015 UESTC Training for Search Algorithm & String<Problem F>
F - Eight Puzzle Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) ...
- UESTC_韩爷的梦 2015 UESTC Training for Search Algorithm & String<Problem N>
N - 韩爷的梦 Time Limit: 200/100MS (Java/Others) Memory Limit: 1300/1300KB (Java/Others) Submit Stat ...
- UESTC_Palindromic String 2015 UESTC Training for Search Algorithm & String<Problem M>
M - Palindromic String Time Limit: 3000/1000MS (Java/Others) Memory Limit: 128000/128000KB (Java ...
- UESTC_Ferris Wheel String 2015 UESTC Training for Search Algorithm & String<Problem L>
L - Ferris Wheel String Time Limit: 3000/1000MS (Java/Others) Memory Limit: 43000/43000KB (Java/ ...
- UESTC_秋实大哥の恋爱物语 2015 UESTC Training for Search Algorithm & String<Problem K>
K - 秋实大哥の恋爱物语 Time Limit: 5000/2000MS (Java/Others) Memory Limit: 32000/32000KB (Java/Others) Su ...
- UESTC_吴队长征婚 2015 UESTC Training for Search Algorithm & String<Problem E>
E - 吴队长征婚 Time Limit: 10000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- UESTC_基爷的中位数 2015 UESTC Training for Search Algorithm & String<Problem D>
D - 基爷的中位数 Time Limit: 5000/3000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- UESTC_基爷与加法等式 2015 UESTC Training for Search Algorithm & String<Problem C>
C - 基爷与加法等式 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Subm ...
- UESTC_邱老师降临小行星 2015 UESTC Training for Search Algorithm & String<Problem B>
B - 邱老师降临小行星 Time Limit: 10000/5000MS (Java/Others) Memory Limit: 65536/65535KB (Java/Others) Su ...
随机推荐
- How to add Leading Zeroes to a Number (Delphi Format)
How to add Leading Zeroes to a Number (Delphi Format) Here's how convert (an integer) number to a st ...
- Keil debugging techniques and alternative printf (SWO function)
One of the basic needs of the embedded software development through the terminal to output debugging ...
- [Winform]js与webbrowser交互
摘要 目前项目中采用的方式是内嵌浏览器的方式,打开本地或者互联网上的h5页面.在开发之前做了一下调研.目前常用的在C#封装的浏览器内核中,Chromium 内核封装有Xilium.Cefglue.Ce ...
- lufylegend:动画
1.动画1 <script type="text/javascript"> var loader,anime,layer; //初始化画布 init(200, &quo ...
- GIS中的数据库.gdb与.mdb的区别
gdb是文件地理数据库,mdb是个人地理数据库,都是数据库文件类型. 个人地理数据库,是以access数据库为基础的个人将数据库格式mdb,可以存储不超过2G的文件,只适合Windows系统下: 文件 ...
- Odoo9发行说明
2015年10月1日,期待已久的Odoo9正式发布.本文是Odoo9正式版发行说明,基于官网资料翻译. 译者: 苏州-微尘原文地址:https://www.odoo.com/page/odoo-9-r ...
- Asp.Net Mvc3.0(MEF依赖注入实例)
前言 在http://www.cnblogs.com/aehyok/p/3386650.html前面一节主要是对MEF进行简单的介绍.本节主要来介绍如何在Asp.Net Mvc3.0中使用MEF. 准 ...
- fabric-ca-server
fabric-ca-server start -b admin:adminpw -d --db.type mysql --db.datasource "root:rootpwd@tcp(17 ...
- 部署包含水晶报表Crystal Reports 的VS.NET2005应用程序[原创]
要部署包含水晶报表Crystal Reports 的应用程序,您需要在生成解决方案之前创建一个安装项目,并且向应用程序中添加必要的合并模块. 1.打开 VS.NET2005 编程IDE. 2.在解决方 ...
- Mysql 编译安装并使用自定义用户启动
本文基于 Redhat Linux 6.7 的环境,Mysql 版本为 5.5.37 安装前的检查 必备的组件,如果没有使用 yum 进行安装,可以使用网上的源,也可以使用本地光盘作为 Yum 源. ...