ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1057. Amount of Degrees

How to solve this problem?Give some Hints please!
Posted by zhangf 29 Jul 2003 16:14
How to solve this problem?Give some Hints please!
Re: How to solve this problem?Give some Hints please!
Posted by zhangf 31 Jul 2003 13:08
> How to solve this problem?Give some Hints please!
The method got from Lalescu Liviu:
1057: I have to calculate how many numbers are from 0 to x, which,
written in
base b, have only digits 0 and 1, and they have exactly k digits of
1. First,
I convert x in base b, I denoted it ax(nx-1), ax(nx-2)...ax(1), ax
(0). I
denote by f(ax,nx,nzeroes) the number of valid numbers from 0 to x,
where
nzeroes is the number of zeroes I have to obtain, and which is nx-k.
Then:
f(ax,nx,nzeroes)=
1) if ax[nx-1]=0, I have to put 0 and return f(ax,nx-1,nzeroes-1)
(remember my
number has to stay below x)
2) if ax[nx-1]=1, I can put 0 and then any combination is below x,
that is we
obtain comb(nx-1,nzeroes-1) variants (comb means binomial coefficient
or
combinations), or put 1 and calculate f(ax,nx-1,nzeroes).
3) if ax[nx-1]>=2, I can put 0 or 1, and obtain
comb(n1-1,nzeroes-1)+comb(n1-1,nzeroes) possibilities, because any
number
generated is below x.