| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:谁能给个清晰的思路In Reply To:谁能给个清晰的思路 Posted by:smallport at 2009-04-27 11:14:48 > 小女子哭求~~~
> ps:ACM的女生太少了
我就是在搞ACM的时候认识我女朋友的,呵呵
-------------------------------------------------------------------------
华丽的分隔线
First note that you only need to count the number of round numbers not exceeding Start-1 and subtract that from the number of round numbers not exceeding Finish. So we are only concerned with counting the number of round numbers not exceeding some number X. Since X can be up to a two billion, we cannot count round numbers one by one.
Consider X in binary. Let N be the number of digits in X.
Let A(x,y) be the number of binary strings with x '0's and y '1's that begin with 0. Let B(x,y) be the number of binary strings with x '0's and y '1's that begin with 1. Let C(x,y) be the number of binary strings with x '0's and y '1's that begin with 0 where each string represents a number not exceeding the number represented by the last x+y digits of X. Let D(x,y) be the number of binary strings with x '0's and y '1's that begin with 1 where each string represents a number not exceeding the number represented by the last x+y digits of X.
We update A, B, C, D using dynamic programming bottom up for each x+y=k, incrementing k until k = N.
The desired result is the sum of all D(x,y) where x+y = N and x>=y, plus the sum of all B(x,y) with x+y=y.
Do this procedure for both Finish and Start-1 and subtract to get answer.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator