Created
July 7, 2014 06:59
-
-
Save kiinlam/29a4365dd6504862b569 to your computer and use it in GitHub Desktop.
dp组合算法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @ref: http://lifesinger.googlecode.com/svn/trunk/lab/2009/combine-test.html | |
* dp组合算法 | |
*/ | |
function dp_combine_yy(a, m) { | |
var t = [[]], r = []; | |
for (var i = 0, n = a.length; i < n; i++) { | |
for (var j = 0, k = t.length; j < k; j++) { | |
var s = t[j].concat([a[i]]); | |
s.length < m ? t.push(s) : r.push(s); | |
} | |
} | |
return r; | |
} | |
dp_combine_yy([1,2,3,4,6],3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment