BZOJ 3028: Food generating function

title

\(~\)
BZOJ 3028
Description

This obviously have to go out to travel, and the last difference is that this time he was going to the universe adventure! We do not discuss how much he NC, he should take some of his illusions anything. Of course, of course you want to help him calculate the number of programs carried by the N items. This time he was ready to take some popular foods, such as: peach Dora, chicken burgers, etc. Of course it Chengde, he have some strange limitations: limitations of each food are as follows:
Chengde Hamburg: an even number
Coke: 0 or 1
chicken: 0, 1, or 2
peach plurality: an odd number of
chicken: a multiple of 4
buns: 0, 1, 2 or 3
potato chips Pork: not more than One.
Bread: a multiple of 3.
Note that here we are obviously too lazy to consider how the food belt with the food, but also that each food are all 'one' as a unit (because it is fantasy thing), even as long as the total adds up to N One solution. Thus, for a given N, you need to calculate the number of programs, and modulo 10007.

Input

Enter a number N, 1 <= n <= 10 ^ 500

Output

If that

Sample Input

Sample input. 1
. 1
Input Sample 2
. 5

Sample Output

Sample output. 1
. 1
Output Sample 2
35

analysis

The generating function can be seen:

Chengde Hamburg: \ (. 1 + X + X ^ 2 + .... 4 ^ = \ {FRAC. 1. 1-X} ^ {2} \)

Coke: \ (. 1 + X \)

Chicken: \ (. 1 + X + X ^ 2 = \ FRAC {3-1} {X ^}. 1-X \)

Multi Peach: \ (X + X + X ^ ^. 3. 5 + ... = \ FRAC {X} ^ {2}. 1-X \)

Chicken: \ (. 1 + X + X ^ ^. 4. 8 + ... = \ FRAC. 1 {{}}. 1. 4-X ^ \)

Buns: \ (. 1 + X + X + X ^ 2 ^. 3 = \ FRAC {4-1} {X ^}. 1-X \)

Potato chips Pork: \ (. 1 + X \)

Bread: \ (. 1 + X + X ^ ^. 3. 6. 9 + ... + X ^ = \ FRAC. 1 {{}}. 3. 1-X ^ \)

It is by \ (\ FRAC {X} {(. 1-X)}. 4 ^ \) .

Then according to a formula, generating function \ (\ FRAC. 1 {} {(. 1-X) n-^} = (. 1 + X + X ^ 2 + ... + X ^. 3) n-^ \) , seeking \ (m \) coefficient is equivalent to the number of combinations \ (. 1-n-C ^ {} _ {}. 1-n-m + \) .

Is then multiplied by \ (X \) is equivalent to the right one, it becomes \ (n-C ^ {} _ {. 1-m-n-2} + \) , requirements of \ (n-\) bits, the answer is \ (C 3_ ^ {n-2} + \) .

code

#include<bits/stdc++.h>
using namespace std;
const int mod=10007;
 
char buf[1<<15],*fs,*ft;
inline char getc() { return (ft==fs&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),ft==fs))?0:*fs++; }
template<typename T>inline void read(T &x)
{
    x=0;
    T f=1, ch=getchar();
    while (!isdigit(ch) && ch^'-') ch=getchar();
    if (ch=='-') f=-1, ch=getchar();
    while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
    x*=f;
}
 
template<typename T>inline void write(T x)
{
    if (!x) { putchar('0'); return ; }
    if (x<0) putchar('-'), x=-x;
    T num=0, ch[20];
    while (x) ch[++num]=x%10+48, x/=10;
    while (num) putchar(ch[num--]);
}
 
inline void exgcd(int a,int b,int &x,int &y)
{
    if (!b)
    {
        x=1,y=0;
        return ;
    }
    exgcd(b,a%b,x,y);
    int tmp=x;
    x=y;
    y=tmp-a/b*y;
}
 
char ch[510];
int main()
{
    scanf("%s",ch+1);
    int len=strlen(ch+1),n=0;
    for (int i=1; i<=len; ++i) n=((n<<1)+(n<<3)+(ch[i]^48))%mod;
    int x,y;
    exgcd(6,mod,x,y);
    x=(x%mod+mod)%mod;
    write((n%mod*(n+1)%mod*(n+2)%mod)*x%mod),puts("");
    return 0;
}

Guess you like

Origin www.cnblogs.com/G-hsm/p/11318529.html