[Bzoj 3209] The number of flowers and gods

Source: Internet
Author: User

A simple digital DP question

But there is only _ builtin_popcountll in my mind (self-respect)

I quickly understood the problem after reading the answer, and there was such a simple question that I did not expect the practice ~ Feeling

 

F [I] indicates the number of digits with 1 being I and less than N.

Then the answer is explain if [I], and f [I] can be messed up from high to low DP with a combination of numbers. O (lgn) 2)

For example, the front I-1 bit has K-bit 1, the first I-bit is 1, followed by J-bit

Then, set the I-th bit to 0. No matter what number the last J-th bit is, it is smaller than N, use the number of combinations to update f [K + L] (0 <= L <= J ).

 

However, after wa for a long time, we found that the modules commonly used in the 10000007 competition were

No! Yes! Quality! Count!

10000007 = 941*10627

Then I used the ferma's Theorem to do this, biubiu ~

You have to calculate the answer by enumeration.

Pay attention to it later.

 

 1 #include <cstdio> 2 typedef long long LL; 3 const int mod=10000007; 4 const int size=64; 5  6 LL n; 7 LL ans; 8 LL c[size][size]; 9 LL f[1024];10 inline LL getint();11 inline void putint(LL);12 inline int lg(LL);13 inline LL mul(LL, LL);14 inline LL pow(LL, LL);15 inline void calc();16 17 int main()18 {19     n=getint();20     ans=1;21     calc();22     putint(ans);23 24     return 0;25 }26 inline LL getint()27 {28     register LL num=0;29     register char ch;30     do ch=getchar(); while (ch<‘0‘ || ch>‘9‘);31     do num=num*10+ch-‘0‘, ch=getchar(); while (ch>=‘0‘ && ch<=‘9‘);32     return num;33 }34 inline void putint(LL num)35 {36     char stack[21];37     register int top=0;38     if (num==0) stack[top=1]=‘0‘;39     for ( ;num;num/=10) stack[++top]=num%10+‘0‘;40     for ( ;top;top--) putchar(stack[top]);41     putchar(‘\n‘);42 }43 inline int lg(LL x)44 {45     int ret=0;46     for ( ;x>1;x>>=1) ret++;47     return ret;48 }49 inline LL mul(LL a, LL b)50 {51     return a*b%mod;52 }53 inline LL pow(LL a, LL b)54 {55     LL c=1;56     for ( ;b;b>>=1)57     {58         if (b & 1) c=mul(c, a);59         a=mul(a, a);60     }61     return c;62 }63 inline void calc()64 {65     for (int i=0;i<64;i++)66     {67         c[i][0]=1;68         for (int j=1;j<i;j++)69             c[i][j]=c[i-1][j-1]+c[i-1][j];70         c[i][i]=1;71     }72     int k=0;73     for (int i=lg(n);i>=0;i--) if ((n>>i) & 1)74     {75         ans=mul(ans, k+1);76         for (int j=1;j<=i;j++)77             ans=mul(ans, pow(k+j, c[i][j]));78         ++k;79     }80 }
Ben silly wa Outang Series

 

[Bzoj 3209] The number of flowers and gods

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.