Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

思路~

Posted by liuyuquan100 at 2011-02-14 11:30:42 on Problem 3252
c(n,m) 表示从n个里取出m的组合数。

对于一个二进制数(b位)。其首位为1.则RN数
1.当b为偶数b=2k时, RN=c(2k-1,2k-1)+c(2k-1,2k-2)+...+c(2k-1,k+1);

由c(2k-1,0)=c(2k-1,2k-1);
  c(2k-1,1)=c(2k-1,2k-2);
  ...
  c(2k-1,k-1)=c(2k-1,k+1);

c(2k-1,0)+c(2k-1,1)+....+c(2k-1,k-1)+c(2k-1,k)+c(2k-1,k+1)+...+c(2k-1,2k-2)+c(2k-1,2k-1)=2^(2k-1); 

即有RN+c(2k-1,k)+RN=2^(2k-1) 

所以RN=[2^(2k-1)-c(2k-1,k)]/2; 

即RN=[2^(b-1)-c(b-1,b/2)]/2; 


2.当b为奇数b=2k+1时,RN=c(2k,2k)+c(2k,2k-1)+...+c(2k,k);

按1的思路,可得,RN=[2^(2k)]/2=[2^(b-1)]/2=2^(b-2);

--------------------------分割线---------------------------- 

问题归结于求<=n的RN(Round Numbers)个数。

1.把n转化为二进制,低位到高位->a[],位数为->index.
2.位数少于index的,即1,2,3 ,... ,index-1  用上面的方面解决。
3.位数为index的,遍历a[],用p,q记录遇到的0,1个数。
由i=(index-1)->0 
遇到1(不是index-1)则处理,就是找出把当前的1变成0的所有RN数:由剩下的长度(即右边二进制位)为i。1的个数为q,0的个数为p+1(第i个位置是0的)。则RN数有,RN=c(i,i)+c(i,i-1)+..+c(i,k) ;  (!!!k的范围!!!!: k+p+1>=i-k+q && k>=0)

注:2,3的RN数之和就是n的RN数。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator