卷积和

摘要:
题意:假定数字$x=d_0d_1d_2d_3...d_{n-1}$,则$F=sum_{i=0}^n{d_id_{n-i-1}}$求$sum_{i=L}^R{F}$的值。解法:只要求出$S=sum_{i=1}^{n-1}{F}$1. 先统计数位小于$n$的数位的。对于接下来剩下的$[frac{tot}{2}]$对,按照有一个确定,有两个确定,有三个确定分类。

题意:

假定数字$x = d_0d_1d_2d_3...d_{n-1}$,则$F(x) = sum_{i=0}^n{d_i d_{n-i-1}}$

求$sum_{i = L}^R {F(i)}$ 的值。

解法:

只要求出 $S(n) = sum_{i = 1}^{n-1} {F(i)}$

1. 先统计数位小于 $n$ 的数位的(分三 / 两种情况)。

2. 考虑枚举数位,假定当前还剩下$len$位没有确认,首先考虑如果长度为奇数,统计一下。

对于接下来剩下的 $[frac{tot}{2}]$ 对,按照有一个确定,有两个确定,有三个确定分类。

$O(log^2n)$

想清楚再写,QAQ

卷积和第1张卷积和第2张
#include <iostream>#include <cstdio>#include <cstring>

#define LL long long
#define P 1000000007LL
#define N 110

using namespacestd;

intnum[N], v[N];
LL cnt[10][10], power[N];

void solve(inttot)
{
    if(tot == 1)
    {
        for(int i = 1;i <= 9;i++)
            cnt[i][i]++;
    }
    else{
        for(int i = 1;i <= 9;i++)
            for(int j = 1;j <= 9;j++)
                cnt[i][j] += 2LL * power[tot-2] %P;
        if(tot == 2) return;
        if(tot & 1)
        {
            for(int i = 1;i <= 9;i++)
                cnt[i][i] += 9LL * power[tot-2] %P;
        }
        LL tmp = (tot-2)/2LL;
        for(int i = 1;i <= 9;i++)
            for(int j = 1;j <= 9;j++)
                cnt[i][j] += (2LL * tmp * power[tot-3] * 9LL) %P;
    }
}

void solve(int tot, intlen)
{
    if(tot & 1)
    {
        int tmp = tot/2 + 1;
        if(v[tmp] == -1)
        {
            for(int i = 1;i <= 9;i++)
                cnt[i][i] += power[len-1];
        }
        else cnt[v[tmp]][v[tmp]] +=power[len];
    }
    for(int i = 1;i <= tot/2;i++)
    {
        if(v[i] >= 0)
            cnt[v[i]][v[tot-i+1]] += 2ll * power[len] %P;
        else{
            if(v[tot-i+1] >= 0)
            {
                for(int j = 1;j <= 9;j++)
                    if(len > 0) cnt[j][v[tot-i+1]] += 2LL * power[len-1] %P;
            }
            else{
                for(int j = 1;j <= 9;j++)
                    for(int k = 1;k <= 9;k++)
                        cnt[j][k] += 2LL * power[len-2] %P;
            }
        }
    }
}

LL calc(LL n)
{
    memset(v, -1, sizeof(v));
    memset(cnt, 0, sizeof(cnt));
    int tot = 0;
    for(;n;n /= 10) num[++tot] = n%10;
    for(int i = 1;i < tot;i++) solve(i);
    for(int i = tot;i >= 1;i--)
    {
        for(int j = (i == tot? 1:0);j < num[i];j++)
            v[i] = j, solve(tot, i-1);
        v[i] =num[i];
    }
    LL ans = 0;
    for(int i = 1;i <= 9;i++)
        for(int j = 1;j <= 9;j++)
        {
            cnt[i][j] %=P;
            ans += (i * (LL)j * cnt[i][j]) %P;
        }
    return ans %P;
}

intmain()
{
    power[0] = 1;
    for(int i = 1;i < N;i++) power[i] = power[i-1] * 10LL %P;
    LL a, b;
    cin >> a >>b;
    cout << (calc(b+1) + P - calc(a)) % P <<endl;
    return 0;
}
View Code

免责声明:内容来源于网络,仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇2017 jq 总结穆里尼奥之皮洛斯式胜利下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

TP框架

Thinkphp框架最初是由于企业级网站和网站的发展而诞生的。它最初诞生于2006年,名为fsc,2007年正式更名为thinkphp。它遵循Apache 2.0协议。定义和调用TP模板所有模板都必须放置在视图文件夹中。规则:一个控制器对应一个文件夹,一个方法对应文件TP模板的调用绝对路径。1.在Application文件夹下创建Admin文件夹,并在Adm...

天气插件(vue)和风天气插件

&lt:“center”:“left”:&lt:v=2.0(函数(d){varc=d.createElement('link')c.rel='stylesheet'.href='http://t.zoukankan.com/https;v=1.4.0'vars=d.createElement;...

爱快路由器的一些注意事项硬件配置+多线负载均衡

以下数据仅供参考:注意:磁带载体的数量因使用环境和带宽大小的不同而不同。此外,请注意32位系统的安装。最大内存为4G,最大内存为3G-----硬盘------安装“爱快路由”时对硬盘的最低要求为1G以上。...

Centos7 挂载

1.Mount命令:Mount语法格式:Mount Mount设备文件信息Mount point(目录)注意:装载点(目录)必须有一个装载CD-ROM驱动器:Mount/dev/cdrom/mnt 2.卸载命令:umount语法格式:umountmount point(directory)3.查看磁盘装载状态/查看磁盘使用情况df4。存储设备通电时自动装载#...

Qt使用镜像源快速安装与更新

如果我们选择在线安装模式,那就更麻烦了,因为下载速度一般不慢。事实上,在中国,Qt图片来源很多,但很少有人使用。原因是Qt图像源做得不好。如果我们导入它,它将自动链接到官方图像源。因为它已经从官方来源同步,没有更改,所以我们无法逐个添加补丁,这太麻烦了。好吧,让我停止胡说八道。让我告诉你如何使用国产Qt图像源。...

sqlserver 计算 百分比

selectltrim+'%'As百分比NUMERIC(P,S)P的默认值是:38S的默认值是:-84~127numeric(a,b)函数有两个参数,前面一个为总的位数,后面一个参数是小数点后的位数,例如numeric(5,2)是总位数为5,小数点后为2位的数,也就是说这个字段的整数位最大是3位。...