red_coder's blog

By red_coder, 12 years ago, In English

suppose we are given two integers M and N such that k1+k2+k3....kM= N

where k1,k2,... are non-negative integers. now we have to print all possible unique combinations along with the numbers of occurence of each combination. for example M= 3 and N=7 so the combinations goes like-

007 3 (3 means 007, 070, 700, 0+0+7=7)

016 6

025 6

034 6

115 3

223 3

...... and so on...

now what is the fastest way to output all the combinations given the integers M and N. M and N can be large...

  • Vote: I like it
  • -49
  • Vote: I do not like it

»
12 years ago, # |
  Vote: I like it +3 Vote: I do not like it

What exactly do you mean by "large"?

»
12 years ago, # |
  Vote: I like it -11 Vote: I do not like it

M can be uptu 400 and N can be uptu 800.