NBUT 1619
来源:互联网 发布:微信看不到淘宝链接 编辑:程序博客网 时间:2024/06/08 13:56
[1619] 递增数字
- 时间限制: 1000 ms 内存限制: 65535 K
- 问题描述
- 我们把数字的高位到低位逐渐变大的数字叫作递增数字,形如0,12344,35799。现在给出区间L和R,请你计算L到R内递增数字的个数。因为个数比较多,将答案输出mod (1e9+7)后输出。
- 输入
- 多组输入,每组输入两个数,分别代表L和R。
数据范围:0<=L<=R<=10^100。 - 输出
- 每组输出一行,表示答案个数mod 1e9+7后的值。
- 样例输入
13 2493 11112345 54321
- 样例输出
102952
- 提示
无
- 来源
2015苏州大学ACM-ICPC集训队选拔赛(1)
注意是大数。
数位DP,模板里改一点就行了。
#include <iostream>#include <stdio.h>#include <math.h>#include <algorithm>#include <string.h>using namespace std;typedef long long LL;const LL maxn = 500+44;const LL inf = 0x3f3f3f3f;const LL mod = 1e9+7;LL num[111];LL dp[111][12];LL dfs(LL pos,LL pre,LL sta,bool limit){if(pos==0) return 1;if(!limit&&dp[pos][sta]!=-1) return dp[pos][sta];LL up=limit?num[pos]:9;LL temp=0;for(LL i=0;i<=up;i++){if(pre==-1){(temp+=dfs(pos-1, i, i+1,limit&&(i==num[pos])))%=mod;}else{if(i<pre){continue;}(temp+=dfs(pos-1,i,i+1,limit&&(i==num[pos])))%=mod;}}if(!limit) dp[pos][sta]=temp;return temp%mod;}LL doit(char x[]){LL cnt=0;LL l=strlen(x);for(LL i=l-1;i>=0;i--){num[++cnt]=x[i]-'0';}return dfs(cnt,-1,0,true);}LL haha(char s[]){LL l=strlen(s);for(LL i=1;i<l;i++){if(s[i]<s[i-1]){return 0;}}return 1;}int main(){memset(dp,-1,sizeof dp);char s1[111],s2[111];while(~scanf("%s %s",s1,s2)){LL k=haha(s1);printf("%lld\n",(mod+doit(s2)-doit(s1)+k)%mod);}}
阅读全文
0 0
- NBUT 1619
- NBUT
- NBUT
- NBUT
- NBUT
- NBUT
- 【NBUT
- NBUT
- NBUT
- NBUT
- NBUT
- NBUT
- nbut 1475
- NBUT 1481
- NBUT 1552
- NBUT 1477
- NBUT 1450
- NBUT 1665
- Hibernate的学习之路十四(事务)
- Spring Cloud学习笔记4——服务容错保护Hystrix
- AI GOD:1013: 小英的咖啡厅
- window下面使用protobuf
- Haskell语言学习笔记(45)Profunctor
- NBUT 1619
- C语言指针详述
- Haskell语言学习笔记(46)Parsec(3)
- NOIP2017 列队 线段树(指针版)+vector
- leveldb:DBIter
- sQL学习(2)
- Android动态设置控件等宽高
- Haskell语言学习笔记(47)Arrow(2)
- UNITY开发中常用的一些API