Skip to content

Instantly share code, notes, and snippets.

@kiinlam
Created July 7, 2014 06:59
Show Gist options
  • Save kiinlam/29a4365dd6504862b569 to your computer and use it in GitHub Desktop.
Save kiinlam/29a4365dd6504862b569 to your computer and use it in GitHub Desktop.
dp组合算法
/*
* @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