卷积和

摘要:
题意:假定数字$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=

随便看看

Jmeter中获取返回结果中的值

在jmeter的测试中,通常需要在下一个请求中使用上一个请求的返回值。如何获得返回值非常重要。插件下载地址为:http://jmeter-plugins.org/wiki/JSONPathExtractor/下载后,将lib文件夹放在jmeter目录中。...

季调方法论

理论与实践“季节性调整原则季节性调整方法分析季节性调整实践中遇到的问题只有同比数据缺少春节效应阅读”通货膨胀的季节性调整和预测模型“通货膨胀预测CPI的季节性调整具有明显的春节效应考虑春节效应的季节性调节春节效应的确定CPI的季节调整基于季节性调整后CPI的预测通货膨胀的修正(应对非洲猪瘟的影响)修订并扩大了季度调查方法的CPI预测读数...

mac格式化重装系统

4.选择“重新安装MacOS”5.按照以下步骤中的提示进行操作。安装需要半个多小时。在此期间无法断开网络,否则需要重新安装...

electron用默认浏览器打开链接的3种实现方式

在使用Electron开发桌面程序的过程中,我们可能经常需要使Electron程序中包含的链接在单击后直接调用系统的默认浏览器打开。仔细阅读文档后,我们都知道它的核心原理是调用系统的默认浏览器,通过Electron shell模块中的openExternal方法打开链接。然而,它的实现有不同的方法,彻底接管和选择性接管。介绍第3章中的有效方法。以上三种方法都...

win10 .net3.5的问题及解决方案

小编下面就介绍win1064位系统无法安装Netframework3.5的两种解决方案吧在Windows10中,当我们安装某些软件的时候会提示“你的电脑上的应用需要使用以下Windows功能:.NETFramework3.5”。但近日有网友反映在windows10_64位系统电脑上安装Netframework3.5,操作时总是遇到失败的情况。下面小编就为大家...

[Oracle]

MyOralceLinux6.5isrunningonVirtualBox.Basicsettingsis4Gmemory,50Ghard-disk,autopartitionwheninstallOL6.5.**Followingseriesofoperationsneedrootprivilege.1.Edit/etc/hostsAddyourhostn...