码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 3028 食物 ——生成函数

时间:2017-03-13 23:54:36      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:string   main   class   lld   std   blog   include   pre   n+1   

把所有东西的生成函数搞出来。

发现结果是x*(1-x)^(-4)

然后把(1-x)^(-4)求逆,得到(1+x+x^2+...)^4

然后考虑次数为n的项前的系数,就相当于选任意四个非负整数构成n的方案数。

大概就是C(n+3,3)

前面还有一项是x,所以n--即可。

然后就A掉了。

#include <cstdio>
#include <cstring>
#define ll long long
const int inv=1668;
const int md=10007;
int n;char s[505];
int main()
{
    scanf("%s",s+1);
    for (int i=1;i<=strlen(s+1);++i)
        n=(10*n+s[i]-‘0‘)%md;
    printf("%lld\n",((ll)n*(n+1)*(n+2)*inv)%(ll)md);
}

  

BZOJ 3028 食物 ——生成函数

标签:string   main   class   lld   std   blog   include   pre   n+1   

原文地址:http://www.cnblogs.com/SfailSth/p/6545639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!