exponential complexity DEMO
来源:互联网 发布:加工中心编程软件app 编辑:程序博客网 时间:2024/06/01 09:00
#quote from MIT 'introduction to computation and programming using python, Revised'def getBinaryRep(n, numDigits): """Assumes n and numDigits are non-negative ints Returns a numDigits str that is a binary representation of n""" result = '' while n > 0: result = str(n%2) + result n = n//2 if len(result) > numDigits: raise ValueError('not enough digits') for i in range(numDigits -len(result)): result = '0' + result return result def genPowerset(L): """Assumes L is a list Returns a list of lists that contains all possible combinations of the elements of L. E.g., if L is [1, 2] it will return a list with elements [], [1], [2], and [1, 2].""" powerset = [] for i in range(0, 2**len(L)): binStr = getBinaryRep(i, len(L)) subset = [] for j in range(len(L)): if binStr[j] == '1': subset.append(L[j]) powerset.append(subset) return powerset
L = ['a', 'b', 'c']
genPowerset(L)
Out[113]: [[], ['c'], ['b'], ['b', 'c'], ['a'], ['a', 'c'], ['a', 'b'], ['a', 'b', 'c']]
0 0
- exponential complexity DEMO
- Exponential Decay demo(Exponential Distribution)
- Lecture 8: Complexity; log, linear, quadratic, exponential algorithms
- selection sort DEMO(linear complexity)
- exponential family
- exponential family
- Exponential families
- Exponential Fitting
- Exponential notation
- System Complexity
- Algorithm Complexity
- Peaks Complexity
- Instant Complexity
- Rademacher complexity
- Radermacher Complexity
- Time Complexity and Space Complexity
- Convolution&Exponential shadow map
- 指数族Exponential Family
- Python内存管理机制
- SDP网络流媒体会话信息描述及应用分析二
- Oracle442个应用场景------------基础应用场景
- Android-循环广告位组件
- Android-风格和主题
- exponential complexity DEMO
- LeetCode OJ 之 Majority Element II(大部分元素2)
- 随记
- 7.2(stm32以太网)
- java第一个类的测试小例子
- LA 2995 & ZOJ2714 Image is Everything
- 三期_day04_Dao层的准备工作_I
- 谨慎使用A2W等字符转换宏
- 数字信号处理公式变程序(五)——仿matlab的spectrogram函数(STFT)