PE 113 Non-bouncy numbers (dp)
来源:互联网 发布:淘宝网9.9元包邮 编辑:程序博客网 时间:2024/06/13 11:57
Non-bouncy numbers
Problem 113
Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468.
Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 66420.
We shall call a positive integer that is neither increasing nor decreasing a "bouncy" number; for example, 155349.
As n increases, the proportion of bouncy numbers below n increases such that there are only 12951 numbers below one-million that are not bouncy and only 277032 non-bouncy numbers below 1010.
How many numbers below a googol (10100) are not bouncy?
题意:
非弹跳数
从左往右,如果每一位数字都大于等于其左边的数字,这样的数被称为上升数,比如134468。
同样地,如果每一位数字都大于等于其右边的数字,这样的数被称为下降数,比如66420。
如果一个正整数既不是上升数也不是下降数,我们就称之为“弹跳”数,比如155349。
随着n的增长,小于n的弹跳数的比例也随之增长;在小于一百万的数中,只有12951个非弹跳数,而小于1010的数中只有277032个非弹跳数。
在小于一古戈尔(10100)的数中有多少个非弹跳数?
题解:这题其实组合数学问题,对非弹跳数进行计数。如果一个数的组成可以看做是从n个数中选k个数的组合情况,我们定义为。
那么定义i(n)和d(n)为位数为n的上升数和下降数的个数。
那么就是:
。
但是我们要排除一些情况,比如11111,22222,33333,这些既是上升数也是下降数的情况。
所以非弹跳数个数T(n)就是:
。
那么结合上面3条公式就是:
进一步化简:
然后简单地写个dp就可以了。
- PE 113 Non-bouncy numbers (dp)
- PE 112 Bouncy numbers (模拟)
- PE 21 Amicable numbers
- Non--Abundant numbers
- BZOJ2986 Non-Squarefree Numbers
- Non-random numbers
- non-random numbers
- PE 23 Non-abundant sums
- PE 2 Even Fibonacci numbers
- bzoj 2986: Non-Squarefree Numbers
- bzoj 2986 Non-Squarefree Numbers
- PE 521【DP】
- PE 290【数位DP】
- PE 240 【DP】
- SPOJ 16637. Non-Square Free Numbers
- 【BZOJ】【P2986】【Non-Squarefree Numbers】【题解】【数论】
- Homework of PE dp 正难则反
- bouncy castle
- 我的LeetCode 题目汇总
- BAT批处理脚本
- 【数据结构】----平衡二叉树怎么自己画?
- MySQL---编程基础
- .NET 基础 一步步 一幕幕[面向对象之构造函数、析构函数]
- PE 113 Non-bouncy numbers (dp)
- 提炼RecyclerView、ListView的通用适配器,大幅减少项目中adapter的代码量
- 跑步用app轨迹画得比较准确的居然是“咕咚”
- 【Android】关于FLAG_ACTIVITY_NEW_TASK 和 taskAffinity
- dos 添加防火墙入站规则
- 2017.1.8 今天反省一下自身
- 【LeetCode】Intersection of Two Arrays 解题报告
- nginx(tengine)使用
- react-native navigator