Bzoj 3209 the digital topic of the god of Flowers (Digital dp)

Source: Internet
Author: User
Tags cmath

Bzoj 3209 the digital topic of the god of Flowers (Digital dp)

 

3209: Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 980 Solved: 460
[Submit] [Status] [Discuss] Description

Background
As we all know, for many years, huashen has abused various major OJ, OI, CF, TC ...... Of course, CH is also included.
Description
It's said that Hua Shen has come to give lectures again this day. As shown in the following example, there are super difficult questions ...... I am sorry again.
The question of huashen is:
Set sum (I) to represent the number of 1 in the binary representation of I. A positive integer N is given.
Sum (I), that is, the product of sum (1)-sum (N.

 

Input

A positive integer N.

 

Output

A number. The answer model is a value of 10000007.

 

Sample Input Example 1

3

Sample Output 1

2
HINT

 



For example 1, 1*1*2 = 2;


Data scope and conventions


For 100% of the data, N ≤ 10 ^ 15

 

Source

Original Memphis


 

 

Idea: Digital dp, for the binary I if it is 1, then there is a I-1 position can be filled with 1 or 0, you can know how many new 1, it should be noted that there are already several numbers before this number.

 

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         # Define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) # define eps 1e-8typedef long ll; # define fre (I, a, B) for (I = a; I <B; I ++) # define mem (t, v) memset (t), v, sizeof (t) # define sf (n) scanf ("% d ", & n) # define sff (a, B) scanf ("% d", & a, & B) # define sfff (a, B, c) scanf ("% d", & a, & B, & c) # define pf printf # define bug pf ("Hi \ n") using namespace std; # define mod 10000007 # define INF 0x3f3f3f # define N 60ll C [N] [N]; // number of combinations ll a [N]; ll n; ll len; void inint () {int I, j; C [0] [0] = 1; fre (I, 1, N) {C [I] [0] = 1; fre (j, 1, I) {C [I] [j] = C [I-1] [j] + C [I-1] [J-1];} C [I] [I] = 1 ;}} void solve () {int bit [N]; int len = 0; while (n) {bit [++ len] = n % 2; n >>= 1 ;}int now = 0; int I, j; for (I = len; I >= 1; I --) if (bit [I]) {for (j = 0; j
          
            0) {if (y & 1) ans = ans * x % mod; y >>=1; x = x * x % mod;} return ans;} int main () {inint (); int I; scanf ("% lld", & n); mem (a, 0); n ++; solve (); ll ans = 1; fre (I, 1, N) ans = ans * pow _ (I, a [I]) % mod; pf ("% lld \ n", ans ); return 0 ;}
          
        
       
      
     
    
   
  
 


 

Memory code: // dp [I] [j] indicates the number of digits of all 1 obtained by the I-bit j # include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         # Define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) # define eps 1e-8typedef long ll; # define fre (I, a, B) for (I = a; I <B; I ++) # define mem (t, v) memset (t), v, sizeof (t) # define sf (n) scanf ("% d ", & n) # define sff (a, B) scanf ("% d", & a, & B) # define sfff (a, B, c) scanf ("% d", & a, & B, & c) # define pf printf # define bug pf ("Hi \ n") using namespace std; # define mod 10000007 # define INF 0x3 F3f3f3f # define N 60ll dp [N] [N]; int bit [N]; ll n; ll dfs (int pos, int n, bool bound) {if (pos = 0) return n? N: 1; if (! Bound & dp [pos] [n]! =-1) return dp [pos] [n]; int up = bound? Bit [pos]: 1; ll ans = 1; int I; fre (I, 0, up + 1) {if (I = 0) ans * = dfs (pos-1, n, bound & I = up); else ans * = dfs (pos-1, n + 1, bound & I = up); if (ans> = mod) ans % = mod;} if (! Bound) dp [pos] [n] = ans; return ans;} ll solve () {int I, len = 0; while (n) {bit [++ len] = n % 2; n >>= 1;} return dfs (len, 0, true) % mod ;} int main () {mem (dp,-1); scanf ("% lld", & n); printf ("% lld \ n", solve (); return 0 ;}
        
       
      
     
    
   
  
 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.