Good Bye 2017 G. New Year and Original Order
G. New Year and Original Order
2 seconds
256 megabytes
standard input
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的更多相关文章
- Good Bye 2017 部分题解
D. New Year and Arbitrary Arrangement 分析 \(dp[i][j]\) 表示已有 \(i\) 个 \(a\) 和 \(j\) 个 \(ab\) 的情况下继续构造能得 ...
- [Codeforces]Good Bye 2017
A - New Year and Counting Cards #pragma comment(linker, "/STACK:102400000,102400000") #inc ...
- Good Bye 2017 A B C
Good Bye 2017 A New Year and Counting Cards 题目链接: http://codeforces.com/contest/908/problem/A 思路: 如果 ...
- 【CF908G】New Year and Original Order(动态规划)
[CF908G]New Year and Original Order(动态规划) 题面 洛谷 CF 题解 设\(f[i][j][k][0/1]\)表示当前填到了第\(i\)位,有\(j\)个大于等于 ...
- 【CF908G】New Year and Original Order 数位DP
[CF908G]New Year and Original Order 题意:令S(i)表示将i中所有数位上的数拿出来,从小到大排序后组成一个新的数的值.如S(50394)=3459.求$\sum\l ...
- 【CF908G】New Year and Original Order
[CF908G]New Year and Original Order 题面 洛谷 题解 设\(f[i][j][k][l]\)表示当前在第\(i\)位有\(j\)位大于等于\(k\),当前有没有卡上界 ...
- Hello 2018, Bye 2017
2017年过去了,过去一年经历了太多,改变了好多好多,可以说人生进入了另一个阶段,有可能是成熟吧. 回顾2017 去年换了新工作,离开了将近工作了8年的公司,不带走一丝云彩,为其任劳任怨,最后没有任何 ...
- Good Bye 2017 E. New Year and Entity Enumeration
先按照绿点进行分块 第一个绿点和最后一个绿点之后很好处理不说了 两个绿点之间的讨论: 有两种方案 1:红(蓝)点和绿点顺序连接,距离为相邻绿点距离(也就是双倍绿点距离) 2:红(蓝)点和绿点的点阵中寻 ...
- Good Bye 2017(送命场)
9815人数场,9500+围观神仙打架...断断续续打Codeforces也快有一年啦,第一次打Good Bye场,满怀前排膜tourist的心愿参加了这场送命场,虽然没看到tourist.不过还是得 ...
随机推荐
- Step1-有序顺序表
#include<stdio.h> #define N 100 typedef struct jcb{ ]; int arrtime; int reqtime; }jcb; jcb job ...
- livecd-creator: UnicodeEncodeError: 'ascii' codec can't encode characters in position 1282-1
通过livecd-creator进行构建ISO过程中出现题目中错误, livecd-creator命令属于包livecd-tools 问题原因: 编码错误,初步判断应该与编码相关的环境变量设置有关 解 ...
- Laravel 的 Events(事件) 及 Observers(观察者)
你是否听说过单一职责原则(single responsibility principle)?我希望是的.它是程序设计的基本原则之一,它基本上的意思就是,一个类有且只有一个职责.换句话说,一个类必须且只 ...
- [Groovy] 学习Groovy的好网站(内容全面)
https://www.tutorialspoint.com/groovy/index.htm
- html5之history对象理解
history对象之pushState,replaceState浏览器有一个history对象,用来保存浏览历史,用户可以通过点击浏览器的后退或前进按钮在历史记录中切换.之前对history的操作的A ...
- 2018.09.23 bzoj1076: [SCOI2008]奖励关(期望+状压dp)
传送门 一道神奇的期望状压dp. 用f[i][j]f[i][j]f[i][j]表示目前在第i轮已选取物品状态为j,从现在到第k轮能得到的最大贡献. 如果我们从前向后推有可能会遇到不合法的情况. 所以我 ...
- 2018.06.30 BZOJ 2342: [Shoi2011]双倍回文(manacher)
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符串 ...
- Spring boot 出现的时间
Spring 4.0 ~ 4.3 不管商业操作如何,Spring还是继续发展, 2013年12月, Spring4.0 发布,这个版本开始支持JDK8 , 甚至比JDK8 的GA版本还要早3个月! 2 ...
- Shell 中expr的使用
1.expr命令一般用于整数值,其一般格式为:expr argument operator argument一般的用法是使用expr做算术运算,如:[root@centos ~]# expr 10 + ...
- 破解Excel密码
https://zhidao.baidu.com/question/98055974.html 方法:1\打开文件2\工具---宏----录制新宏---输入名字如:aa3\停止录制(这样得到一个空宏) ...