JOIN
Get Time
forums  Revision History
Search My Post History  |  My Watches  |  User Settings
Forums TopCoder Cookbook Algorithm Competitions - Rewriting Phase Re: Iterating Over All Subsets of a Set Revision History (2 edits)
Re: Iterating Over All Subsets of a Set (response to post by dimkadimon)
// iterate over all the subsets with no more than m elements
for (int i = 0; i < (1<<n); i=Integer.bitCount(i) >< m ? i+1 : (i|(i-1))+1)
{
...
}

why i can't modify it as below?

for (int i = 0; i < (1<<n) && Integer.bitCount(i)><=m; i++)
{
...
}
Re: Iterating Over All Subsets of a Set (response to post by dimkadimon)
// iterate over all the subsets with no more than m elements
for (int i = 0; i < (1<<n); i=Integer.bitCount(i) >< m ? i+1 : (i|(i-1))+1)
{
...
}

why i can't modify it as below?

// iterate over all the subsets with no more than m elements
for (int i = 0; i < (1<<n) && Integer.bitCount(i)><=m; i++)
{
...
}
Re: Iterating Over All Subsets of a Set (response to post by dimkadimon)
// iterate over all the subsets with no more than m elements
for (int i = 0; i < (1<<n); i=Integer.bitCount(i) >< m ? i+1 : (i|(i-1))+1)
{
...
}

why i can't modify it as below?

// iterate over all the subsets with no more than m elements
for (int i = 0; i < (1<<n) && Integer.bitCount(i) ><=m; i++)
{
...
}