Created
March 25, 2017 11:42
-
-
Save thinkphp/4abe5afe080bc0b52e10114335ded576 to your computer and use it in GitHub Desktop.
This file contains 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
def Subset n | |
arr = [0]*n | |
begin | |
arr[n-1] += 1 | |
for i in (n-1).downto(1) | |
if arr[i] > 1 then | |
arr[ i ] -= 2 | |
arr[i - 1] += 1 | |
end | |
end | |
for i in 0..n-1 | |
if arr[i] != 0 then | |
print (i+1) | |
end | |
end | |
s = 0 | |
for i in 0..n-1 | |
if arr[i] then | |
s += arr[i] | |
end | |
end | |
print "\n" | |
end while s < n | |
end | |
Subset 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment