链接:https://ac.nowcoder.com/acm/contest/338/F
来源:牛客网

题目描述

AFei loves numbers. He defines the natural number containing "520" as the AFei number, such as 1234520, 8752012 and 5201314. Now he wants to know how many AFei numbers are not greater than n.

输入描述:

The first line contains an integer T (1 <= T <= 100 ).

The following T lines contain an interger n ( 0 <= n <= 1e18 ).

输出描述:

For the last T lines, output the total numbers of AFei numbers that are not greater than n.
示例1

输入

复制

2
1000
5520

输出

复制

1
16

说明

For the first case, only 520 is AFei number.

For the second case, 520,1520, 2520, 3520, 4520, 5200, 5201, 5202, 5203, 5204, 5205, 5206, 5207, 5208, 5209 and 5520 are AFei number. So there are 16 AFei numbers.
题意:给定一个自然数n(<=n<=1e18),求[,n]里有多少个整数包含“”(即所谓Afei数的数量)

解题思路: 数位DP入门题。

首先,设dp[i]表示长度为i的AFei数的数量。发现这样不行,因为按数位计算的话,每次只会考虑一位,而AFei 数的特征是要有连续的三位,并且第一位是5,第二位是2,第三位是0。

这说明需要记录前两位,那么设dp[i][j]表示以j开头,后面还有i位的AFei数的数量。比如dp[][]就是表示形 如25****的数字中,AFei数的数量。因为n只有1e18,所以i最大不超过19,而j是用来记录前两位的,所以j最 大不超过99,所以声明dp数组的时候只需要long long dp[][]即可。

AFei数并没有规定“”的数量有多少个,碰到这样的我习惯性反着算,也就是用dp[i][j]表示以j开头,后面 还有i位的不是AFei数的数量。算到最后再减一下就行了。

状态转移方程:
举个例子:以f(****)表示形如****的不是afei数的数量,显然:f[****]=f[***]+f[***]+f[***]+f[***]+f[***]+f[***]+f[***]+f[***]+f[***]+f[***]也就是dp[][] = σ

F Find the AFei Numbers的更多相关文章

  1. F. Igor and Interesting Numbers

    http://codeforces.com/contest/747/problem/F cf #387 div2 problem f 非常好的一道题.看完题,然后就不知道怎么做,感觉是dp,但是不知道 ...

  2. CSU 2018年12月月赛 F(2218): Finding prime numbers

    Description xrdog has a number set. There are 95 numbers in this set. They all have something in com ...

  3. 湖南大学第十四届ACM程序设计新生杯(重现赛)

    RANK  0 题数 0 期末复习没有参加,补几道喜欢的题. A: AFei Loves Magic  签到 思路 :不需考虑 碰撞 直接计算最终状态即可. #include<bits/stdc ...

  4. F.Cards with Numbers

    链接:https://ac.nowcoder.com/acm/contest/908/F 题意: AFei has many cards. Each card has a number written ...

  5. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  6. Java [Leetcode 357]Count Numbers with Unique Digits

    题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. ...

  7. [转]查询表达式 (F#)

    本文转自:http://msdn.microsoft.com/zh-cn/library/hh225374.aspx 查询表达式可以查询数据源并将数据是一种预期形式.             查询表达 ...

  8. Python中用format函数格式化字符串

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存. 1.百分号方式 语法:%[( ...

  9. python基础之day2

    python基本数据类型 1.数字 int(整型)      在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647  在64位系统 ...

随机推荐

  1. Mysql 数据库中9大对象

    MySql 数据库9中对象1.表2.索引3.视图4.图表:数据库表之间的关系视图,并不常用5.规则6.缺省值:数据列的默认值7.触发器8.存储过程9.用户

  2. CentOS 7系统安装nginx+php

    安装介绍1.系统环境CentOS7 2.nginx版本1.12 3.PHP版本7.2 下载地址 4.MySQL版本5.7 安装nginx添加centos7的 nginx yum源 然后执行安装 sud ...

  3. Codeforces917E

    //#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #i ...

  4. [AHOI2008]紧急集合 / 聚会(LCA)

    [AHOI2008]紧急集合 / 聚会 题目描述 欢乐岛上有个非常好玩的游戏,叫做"紧急集合".在岛上分散有N个等待点,有N-1条道路连接着它们,每一条道路都连接某两个等待点,且通 ...

  5. VNware上安装虚拟机Ubuntu16.10 并安装petalinux(版本问题的坑 弃帖 另开一帖)

    1.下载Ubuntu镜像文件 最新版本:https://ubuntu.com/download/desktop 老版本:http://old-releases.ubuntu.com/releases/ ...

  6. 线程中sleep和wait方法的区别

    sleep() 方法: 线程主动放弃CPU,使得线程在指定的时间内进入阻塞状态,不能得到CPU 时间,指定的时间一过,线程重新进入可执行状态.典型地,sleep()被用在等待某个资源就绪的情形:测试发 ...

  7. MongoDB Compass管理工具下载、安装和使用

    内容来自:https://jingyan.baidu.com/article/925f8cb884f6f8c0dce0565a.html ,https://blog.csdn.net/bg101775 ...

  8. hdu 4845 : 拯救大兵瑞恩 (bfs+状态压缩)

    题目链接 #include<bits/stdc++.h> using namespace std; typedef long long LL; int n,m,p,s,k; ,,,-}; ...

  9. c#类的定义,c#中的关健字,C#标识符

    什么是类:一种数数据结构,存储数据成员,方法成员,和其它的内容,便 于方便 谳用C#语法: class 类名{ //TODO} C#中关键字(小写)不能作为方法名,类名,命名空间名等, static ...

  10. composer proc_open(): fork failed – Cannot allocate memory

    一般小的VPS 才1G内存,如果使用composer会提示内存不足的现象 解决办法,可以使用交换内存 直接命令 /bin/dd if=/dev/zero of=/var/swap.1 bs=1M co ...