F Find the AFei Numbers
链接:https://ac.nowcoder.com/acm/contest/338/F
来源:牛客网
题目描述
输入描述:
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.
说明
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的更多相关文章
- F. Igor and Interesting Numbers
http://codeforces.com/contest/747/problem/F cf #387 div2 problem f 非常好的一道题.看完题,然后就不知道怎么做,感觉是dp,但是不知道 ...
- 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 ...
- 湖南大学第十四届ACM程序设计新生杯(重现赛)
RANK 0 题数 0 期末复习没有参加,补几道喜欢的题. A: AFei Loves Magic 签到 思路 :不需考虑 碰撞 直接计算最终状态即可. #include<bits/stdc ...
- F.Cards with Numbers
链接:https://ac.nowcoder.com/acm/contest/908/F 题意: AFei has many cards. Each card has a number written ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- 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. ...
- [转]查询表达式 (F#)
本文转自:http://msdn.microsoft.com/zh-cn/library/hh225374.aspx 查询表达式可以查询数据源并将数据是一种预期形式. 查询表达 ...
- Python中用format函数格式化字符串
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存. 1.百分号方式 语法:%[( ...
- python基础之day2
python基本数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位系统 ...
随机推荐
- Object中有哪些公用方法?
clone()方法 实现对象的浅复制,只有实现了Cloneable接口才能调用该方法. toString()方法 返回该对象的字符串表示. equals()方法: 在Object中与“==”的定义是一 ...
- git上传文件夹的问题
使用git上传文件夹一定要注意,文件夹里面至少有一个文件,因为git不能管理空文件夹 所以上传就会不成功
- ltp-ddt 加入sram 需要修改的部分
./platform/fmxx-psoc-db add sram 将nor部分移植过来 # @name NOR read write test using dd # @desc Perform NOR ...
- image按钮新增的width属性和height属性
代码实例: test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset ...
- django之mysql数据库的配置和orm交互
一:django默认数据库的配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path. ...
- 为应用程序池 ''DefaultAppPool'' 提供服务的进程意外终止。进程 ID 是 ''xxx''问题的解决方法
网上提供了很多办法,都未解决. 解决过程一波三折,依次用了下列方法: 1.解决办法 点击“开始”-“控制面板”-“管理工具”-“组件服务”-“计算机”-“我的电脑”-“DCOM”选项, 选择其下的“I ...
- layoutSubviews 详解
ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size - (void)sizeToFit ------- - (void)layoutSubview ...
- ProxyImpl 类
package com.test.mvp.mvpdemo.mvp.v7.proxy; import com.test.mvp.mvpdemo.mvp.v7.basemvp.BasePresenter; ...
- ArayList的一些常用法<一> 转
转:http://yy.azj.blog.163.com/blog/static/18508700320122893451389/ import java.util.ArrayList; import ...
- php面试专题---MYSQL查询语句优化
php面试专题---MYSQL查询语句优化 一.总结 一句话总结: mysql的性能优化包罗甚广: 索引优化,查询优化,查询缓存,服务器设置优化,操作系统和硬件优化,应用层面优化(web服务器,缓存) ...
举个例子:以f(****)表示形如****的不是afei数的数量,显然:f[****]=f[***]+f[***]+f[***]+f[***]+f[***]+f[***]+f[***]+f[***]+f[***]+f[***]也就是dp[][] = σ