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. PAT 1078 字符串压缩与解压(20)(代码+思路)

    1078 字符串压缩与解压(20 分) 文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示.例如 ccccc 就用 5c 来表 ...

  2. sdk接入

    文档 http://blog.csdn.net/chenjie19891104/article/details/42217281 视频: https://chuanke.baidu.com/v2869 ...

  3. zabbix分布式系统监视

    http://blog.chinaunix.net/uid-25266990-id-3380929.html

  4. JMeter中用java修改文件名称

    import java.io.File; String NewDataPath=bsh.args[0]; File SrcFile= new File(NewDataPath+"AutoTe ...

  5. [Eclipse]Eclipse里对XML进行注释的快捷键

    eclipse中编辑java或C/C++文件时,注释的快捷键均为 "CTRL + / ",编辑xml文件时,该快捷键无效. eclipse 针对 XML 注释:CTRL + SHI ...

  6. 优秀UX设计师的八条黄金法则

    与用户保持亲密   成为成功的UX设计师最重要的先决条件之一就是与用户保持紧密的联系,以发现和了解他们的需求和爱好.理想情况下你应该让自己完全地成为产品用户,因为只有这样你才能理解背后的动机.“这样的 ...

  7. SQLALchemy--ORM框架

    SQLAlchemy 1.介绍 SQLAlchemy是一个基于Python实现的ORM框架.该框架建立在 DB API之上,使用关系对象映射进行数据库操作,简言之便是:将类和对象转换成SQL,然后使用 ...

  8. Python特殊方法

    # __slots__如果要限制添加的属性,例如,Student类只允许添加 name.gender和score 这3个属性,就可以利用Python的一个特殊的__slots__来实现. # __sl ...

  9. HDU 2037 今年暑假不AC (区间贪心)

    题意:又是中文题... 析:先说一下区间贪心的一个定理,选择不相交的区间:数轴上有n个开区间(ai, bi).选择尽量多的区间,使得这些区间两两不相交,贪心策略是,一定是选bi小的.(想一下为什么). ...

  10. Java 增强 for 循环

    Java 增强 for 循环 Java5 引入了一种主要用于数组的增强型 for 循环. Java 增强 for 循环语法格式如下: for(声明语句 : 表达式) { //代码句子 } 声明语句:声 ...