码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • C. Add One--Divide by Zero 2021 and Codeforces Round #714 (Div. 2)


    Divide by Zero 2021 and Codeforces Round #714 (Div. 2)

    C. Add One

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    You are given an integer nn. You have to apply mm operations to it.

    In a single operation, you must replace every digit dd of the number with the decimal representation of integer d+1d+1. For example, 19121912 becomes 2102321023 after applying the operation once.

    You have to find the length of nn after applying mm operations. Since the answer can be very large, print it modulo 109+7109+7.

    Input

    The first line contains a single integer tt (1≤t≤2⋅1051≤t≤2⋅105) — the number of test cases.

    The only line of each test case contains two integers nn (1≤n≤1091≤n≤109) and mm (1≤m≤2⋅1051≤m≤2⋅105) — the initial number and the number of operations.

    Output

    For each test case output the length of the resulting number modulo 109+7109+7.

    Example

    input

    Copy

    5
    1912 1
    5 6
    999 1
    88 2
    12 100
    

    output

    Copy

    5
    2
    6
    4
    2115
    

    Note

    For the first test, 19121912 becomes 2102321023 after 11 operation which is of length 55.

    For the second test, 55 becomes 2121 after 66 operations which is of length 22.

    For the third test, 999999 becomes 101010101010 after 11 operation which is of length 66.

    For the fourth test, 8888 becomes 10101010 after 22 operations which is of length 44.

    =========================================================================

    对于每一个数字其操作固定操作次数带来的效果也是固定的,故我们可以预处理出每种数字操作m次的长度。 dp[i][j]代表操作i次,j数字获得的长度, 一般的0-8,操作i次获得的长度是j+1,操作i-1次获得的长度,而对于9来说,是i-1次,获得0,1长度的总和。

    1. # include<iostream>
    2. # define mod 1000000007
    3. using namespace std;
    4. typedef long long int ll;
    5. ll dp[200000+10][10];
    6. int main ()
    7. {
    8. for(int i=0;i<=9;i++)
    9. {
    10. dp[0][i]=1;
    11. }
    12. for(int i=1;i<=200000;i++)
    13. {
    14. for(int j=0;j<9;j++)
    15. {
    16. dp[i][j]=dp[i-1][j+1];
    17. }
    18. dp[i][9]=(dp[i-1][0]+dp[i-1][1])%mod;
    19. }
    20. int t;
    21. cin>>t;
    22. while(t--)
    23. {
    24. ll n,m;
    25. scanf("%lld%lld",&n,&m);
    26. while(n)
    27. {
    28. ans=(ans+dp[m][n%10])%mod;
    29. n/=10;
    30. }
    31. cout<<ans<<'\n';
    32. }
    33. return 0;
    34. }

  • 相关阅读:
    C++ 统计程序运行时间
    华为OD机试-机器人走迷宫
    GLTF格式解析
    java进行系统的限流实现--Guava RateLimiter、简单计数、滑窗计数、信号量、令牌桶
    微信小程序相机相册授权后,需要重启客户端才能正常调用相机,无法调起窗口选择图片,无反应解决方案
    Vue3+node.js实战项目网易云音乐APP(二)
    IDEA .iml文件及.idea文件夹详解
    IDEA 中贼好用的插件-开发利器
    5.系统设计的工作内容与技能工具有哪些?
    数据流与重定向,vim练习,grep过滤练习,cut练习
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/125408184
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号