链接: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. Linux架构之Rsync守护进程推和拉

    第三十三章 Rsync服务 33.1)Rsync基本概述 rsync是一款开源.快速.多功能.可实现全量及增量的本地或远程数据同步备份的优秀工具.rsync软件适用于Unix/linux/Window ...

  2. Oracle 附加日志(supplemental log)

    参考资料: 1.https://blog.csdn.net/li19236/article/details/41621179

  3. a[b]和b[a]区别

    #include <stdio.h> main() { char a[5] = "abcd"; int b = 3; printf("%c\n",a ...

  4. redis不重启之rdb数据切换到aof数据

    温馨提示: 要实现不重启从rdb切换到aof,redis的版本必须要在2.2以上. [root@pyyuc /data ::]#redis-server -v Redis server v= sha= ...

  5. 如何安装 mcrypt

    #cd libmcrypt-2.5.8 #./configure #make #make install 说明:libmcript默认安装在/usr/local3.安装mhash #tar -zxvf ...

  6. 暴力&打表

    _LH巨神好像不太会打表,这里来普及一下 还有暴力这么重要的东西网上讲的人竟然不多…… 一.打表 打表,就是针对一些输入数据比较小的题目的一种骗分技巧,当然有时候也可以在正解或暴力中起一定优化作用. ...

  7. java 将MySql数据库中的数据(某一列)取出放入数组中 转

    转:http://blog.csdn.net/ewili/article/details/8605638 假设mysql中test数据库中有个表式score,有数据,我只取第一列的数据出来: publ ...

  8. QT5 QTreeView添加右键菜单

    C++ QT5学习--QTreeView控件创建右键菜单 QTreeView是QWidget的子类,我们再改写QTreeView类的时候,注意的是继承关系. 1.TreeView.h class Tr ...

  9. custom serializer for just one property in Json.NET

    Json序列化的时候跳过加密字段 字段类定义如下 public class Field { public bool IsEncrypted { get; set; } public string Na ...

  10. HDU6719 Strassen(__int128)

    HDU6719 Strassen 直接照题目模拟,数据范围最大不会超过__int128. 时间复杂度为 \(O(\log n)\) . #include<bits/stdc++.h> us ...