G. New Year and Original Order

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Let S(n) denote the number that represents the digits of n in sorted order. For example, S(1) = 1, S(5) = 5, S(50394) = 3459, S(353535) = 333555.

Given a number X, compute modulo 109 + 7.

Input

The first line of input will contain the integer X (1 ≤ X ≤ 10700).

Output

Print a single integer, the answer to the question.

Examples

Input

21

Output

195

Input

345342

Output

390548434

Note

The first few values of S are 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 12. The sum of these values is 195.

tls原话:最简单的数位dp,出题人成功骗过验题人放在了G。

Oh...uuu...原来是简单的数位dp...等等...tls的简单,莫不是.....

#include<bits/stdc++.h>
#define LL long long
using namespace std;
char s[];
int dp[][][],res;
const int mod=1e9+;
int main()
{
cin>>s;
int len=strlen(s);
int ll,kk,i,j,k,l,m;
for(i=;i<=;i++)
{
dp[][][]=;
for(j=;j<len;j++)
for(k=;k<=j;k++)
for(l=;l<=;l++)
for(m=;m<=;m++)
{
if(m<s[j]-'') ll=;
else if(m==s[j]-'') ll=l;
else if(l) continue;
else ll=;
if(m>=i) kk=k+;
else kk=k;
dp[j+][kk][ll]=(dp[j+][kk][ll]+dp[j][k][l])%mod;
}
for(j=,k=;j<=len;j++)
{
res=(res+(LL)k*(dp[len][j][]+dp[len][j][]))%mod;
k=(k*10ll+)%mod;
}
for(j=;j<=len;j++)
for(k=;k<=j;k++)
for(l=;l<=;l++)
dp[j][k][l]=;
}
cout<<res<<endl;
return ;
}

九月巨巨的滚动数组:

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+,maxn=;
#define LL long long
LL sum[maxn][],dp[maxn][];
string s;
inline void Update(LL &x,LL y)
{
x=(x+y)%mod;
}
void Clear()
{
memset(dp,,sizeof(dp));
memset(sum,,sizeof(sum));
dp[][]=;
}
int main()
{
cin>>s;
int len=s.length();
LL ans=;
for(int l=;l<=;l++)
{
Clear();
for(int i=;i<len;i++)
for(int j=;j<;j++)
for(int k=;k<=;k++)
{
if(!j&&k>s[i]-'') continue;
Update(dp[i+][j|k<s[i]-''],dp[i][j]); ///j和k<s[i] 任意一个是1就为1
if(k<l) Update(sum[i+1][j|k<s[i]-'0'],sum[i][j]);
else Update(sum[i+1][j|k<s[i]-'0'],(sum[i][j]*10+dp[i][j])%mod);
}
Update(ans,sum[len][]);
Update(ans,sum[len][]);
}
cout<<ans<<endl;
return ;
}

Good Bye 2017 G. New Year and Original Order的更多相关文章

  1. Good Bye 2017 部分题解

    D. New Year and Arbitrary Arrangement 分析 \(dp[i][j]\) 表示已有 \(i\) 个 \(a\) 和 \(j\) 个 \(ab\) 的情况下继续构造能得 ...

  2. [Codeforces]Good Bye 2017

    A - New Year and Counting Cards #pragma comment(linker, "/STACK:102400000,102400000") #inc ...

  3. Good Bye 2017 A B C

    Good Bye 2017 A New Year and Counting Cards 题目链接: http://codeforces.com/contest/908/problem/A 思路: 如果 ...

  4. 【CF908G】New Year and Original Order(动态规划)

    [CF908G]New Year and Original Order(动态规划) 题面 洛谷 CF 题解 设\(f[i][j][k][0/1]\)表示当前填到了第\(i\)位,有\(j\)个大于等于 ...

  5. 【CF908G】New Year and Original Order 数位DP

    [CF908G]New Year and Original Order 题意:令S(i)表示将i中所有数位上的数拿出来,从小到大排序后组成一个新的数的值.如S(50394)=3459.求$\sum\l ...

  6. 【CF908G】New Year and Original Order

    [CF908G]New Year and Original Order 题面 洛谷 题解 设\(f[i][j][k][l]\)表示当前在第\(i\)位有\(j\)位大于等于\(k\),当前有没有卡上界 ...

  7. Hello 2018, Bye 2017

    2017年过去了,过去一年经历了太多,改变了好多好多,可以说人生进入了另一个阶段,有可能是成熟吧. 回顾2017 去年换了新工作,离开了将近工作了8年的公司,不带走一丝云彩,为其任劳任怨,最后没有任何 ...

  8. Good Bye 2017 E. New Year and Entity Enumeration

    先按照绿点进行分块 第一个绿点和最后一个绿点之后很好处理不说了 两个绿点之间的讨论: 有两种方案 1:红(蓝)点和绿点顺序连接,距离为相邻绿点距离(也就是双倍绿点距离) 2:红(蓝)点和绿点的点阵中寻 ...

  9. Good Bye 2017(送命场)

    9815人数场,9500+围观神仙打架...断断续续打Codeforces也快有一年啦,第一次打Good Bye场,满怀前排膜tourist的心愿参加了这场送命场,虽然没看到tourist.不过还是得 ...

随机推荐

  1. VK Cup 2016 D. Bear and Two Paths 模拟

    D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. linux小白

    1. linux下加域名. 文件是在/etc/hosts    中间加的tab键 192.168.0.1 baidu.com linux下测试网页可以用 wget www.baidu.com  这个命 ...

  3. phonegap android插件,启动activity并返回值

    Your execute menthod is not quite right. When you do: return new PluginResult(PluginResult.Status.OK ...

  4. [docker]mesos集群的启动脚本

    宿主机的IP地址列表 mesos-lb:192.168.253.159 mesos-marathon:192.168.253.159 mesos-master:192.168.253.159 meso ...

  5. python3.4用循环往mysql5.7中写数据并输出

    #!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ pyt ...

  6. MySQL通过游标来实现通过查询记录集循环

    /*我们有时候会遇到需要对 从A表查询的结果集S_S 的记录 进行遍历并做一些操作(如插入),且这些操作需要的数据或许部分来自S_S集合*//*临时存储过程,没办法,不能直接在查询窗口做这些事.*/d ...

  7. 2017 pycharm 激活码

    BIG3CLIK6F-eyJsaWNlbnNlSWQiOiJCSUczQ0xJSzZGIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...

  8. day05(Object,tostring(),equals(),System,Date,SimpleDateFormat,拆装箱,正则表达式)

    Object类, 是所应类的父类: 拥有自己的方法:常用的    红颜色标记的为常用的方法 toString() 用法:打印对象的地址值 getClass() 获取当前类的字节码文件getName() ...

  9. 解码Base64,并保存图片至本地

    五一去了具有诗情画意的城市---杭州,今天是假期结束后回来上班的第一天,玩饱之后回来,确实精神抖擞了不少; 前段时间开发了有关电子签名的需求,其中有个关于解码Base64图片的知识点,值得关注一下; ...

  10. 求解1^2+2^2+3^2+4^2+...+n^2的方法(求解1平方加2平方加3平方...加n平方的和)

    利用公式 (n-1)3 = n3 -3n2 +3n-1 设 S3 = 13 +23 +33 +43 +...+n3 及 S2 = 12 +22 +32 +42 +...+n2 及 S1 = 1 +2 ...