List of all binary combinations for a number in Java

后端 未结 6 1000
后悔当初
后悔当初 2021-01-14 05:15

I am working on a project involving \"Dynamic Programming\" and am struck on this trivial thing, please help.

Suppose I take 4 as an input, I want to display somethi

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-14 05:48

    I'm a bit lost as to how you'd apply dynamic programming to this. It's just a matter of counting from 0 to one less than the specified maximum value (where the maximum value is 1 shifted left the specified number of bits).

    Edit: I should add that there are other possibilities (e.g., gray codes) but absent some reason to do otherwise, simple binary counting is probably the simplest to implement.

提交回复
热议问题