链接: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. 2018-8-10-sublime-Text-正则替换

    title author date CreateTime categories sublime Text 正则替换 lindexi 2018-08-10 19:16:52 +0800 2018-2-1 ...

  2. uboot中Kconfig架构的理解

    1./u-boot-2019.07/Kconfig 是顶层Kconfig mainmenu "U-Boot $UBOOTVERSION Configuration"  #这是总me ...

  3. springboot集成hibernate

    package com.jxd.Boot.hibernate.dao.impl; import java.util.List; import javax.persistence.EntityManag ...

  4. R语言把DataFrame的一行变成向量

    在R语言里面,DataFrame的一列数据本质上可以认为是一个向量或列表,但是一行数据不是. 今天有一个31列的数据集,由于放在第一行的变量名格式不规范,读入数据的时候不能顺带读入变量名.于是跳过首行 ...

  5. ORACLE错误:ORA-28001: the password has expired解决方法

    Oracle提示错误消息ORA-28001: the password has expired,是由于Oracle11G的新特性所致, Oracle11G创建用户时缺省密码过期限制是180天(即6个月 ...

  6. vue动态路由传值以及get传值及编程式导航

    1.动态路由传值 1.配置路由处 { path: '/content/:id', component: Content }, // 动态路由 2.对应页面传值 <router-link :to= ...

  7. react-navigation 实战

    npm install --save react-navigation 1.测试TabNavigator.StackNavigator和DrawerNavigator (1)新建HomeScreen. ...

  8. 双轴按键摇杆控制器控制TFTLCD(使用ADC1双通道DMA传输)

    实验使用如下所示的双轴按键摇杆控制器,来控制TFTLCD上显示的直线.首先介绍一下双轴按键摇杆控制器.原理:十字摇杆为一个双向的10K电阻器,随着摇杆方向不同,抽头的阻值随着变化.本模块使用5V供电( ...

  9. 理解CSS中position的各个值

    static position的默认值,没有定位,元素在normal flow中: fixed 相对于浏览器左上角定位: relative 相对定位元素,其位置根据其在normal flow中的位置来 ...

  10. jenkins持续集成、插件以及凭据

    Jenkins介绍 Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能. Jenkins功能包括: ...