---恢复内容开始---

Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.

Help Kurt find the maximum possible product of digits among all integers from 1 to n.

Input

The only input line contains the integer nn (1≤n≤2⋅109).

Output

Print the maximum product of digits among all integers from 1 to n.

Examples
Input

Copy
390
Output

Copy
216
Input

Copy
7
Output

Copy
7
Input

Copy
1000000000
Output

Copy
387420489
Note

In the first example the maximum product is achieved for 389389 (the product of digits is 3⋅8⋅9=216).

In the second example the maximum product is achieved for 77 (the product of digits is 7).

In the third example the maximum product is achieved for 99999999 (the product of digits is 99=38742048999).

题意:给出n,找出不大于n的一个数,试其乘积最大。

思路:对于一个位置上的数,①可以保持不变,②可以使其变成9,前置位-1.

这样我们可以递归枚举。

 #include<bits/stdc++.h>
using namespace std; int n; int cal(int n)
{
if(n == )return ;
else if(n < )return n;
else
{
return max(cal(n/)*(n%),cal(n/-)*);
}
} int main()
{
scanf("%d",&n);
printf("%d\n",cal(n));
}

---恢复内容结束---

B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)的更多相关文章

  1. [题解] Codeforces Round #549 (Div. 2) B. Nirvana

    Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...

  2. Codeforces Round #549 (Div. 1)

    今天试图用typora写题解 真开心 参考 你会发现有很多都是参考的..zblzbl Codeforces Round #549 (Div. 1) 最近脑子不行啦 需要cf来缓解一下 A. The B ...

  3. Codeforces Round #549 (Div. 2)B. Nirvana

    B. Nirvana time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  4. Codeforces Round #549 (Div. 2) 训练实录 (5/6)

    The Doors +0 找出输入的01数列里,0或者1先出完的的下标. Nirvana +3 输入n,求1到n的数字,哪个数逐位相乘的积最大,输出最大积. 思路是按位比较,从低到高,依次把小位换成全 ...

  5. CodeForces Round #549 Div.2

    A. The Doors 代码: #include <bits/stdc++.h> using namespace std; ; int N; , One = ; int a[maxn], ...

  6. [ Codeforces Round #549 (Div. 2)][D. The Beatles][exgcd]

    https://codeforces.com/contest/1143/problem/D D. The Beatles time limit per test 1 second memory lim ...

  7. Codeforces Round #549 (Div. 2) Solution

    传送门 A.The Doors 看懂题目就会写的题 给一个 $01$ 序列,找到最早的位置使得 $0$ 或 $1$ 已经全部出现 #include<iostream> #include&l ...

  8. Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)

    https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y ...

  9. Codeforces Round #549 (Div. 2) E 倍增处理按排列顺序的上一个位置

    https://codeforces.com/contest/1143/problem/E 题意 p为n的一个排列,给出有m个数字的数组a,q次询问,每次询问a数组区间[l,r]中是否存在子序列为p的 ...

随机推荐

  1. Luogu P4643 【模板】动态dp

    题目链接 Luogu P4643 题解 猫锟在WC2018讲的黑科技--动态DP,就是一个画风正常的DP问题再加上一个动态修改操作,就像这道题一样.(这道题也是PPT中的例题) 动态DP的一个套路是把 ...

  2. Loj 10115 「一本通 4.1 例 3」校门外的树 (树状数组)

    题目链接:https://loj.ac/problem/10115 题目描述 原题来自:Vijos P1448 校门外有很多树,学校决定在某个时刻在某一段种上一种树,保证任一时刻不会出现两段相同种类的 ...

  3. vscode设置python3.7调试环境(已更新)

    汇总系列:https://www.cnblogs.com/dunitian/p/4822808.html#ai CentOS安装Python3.7:https://www.cnblogs.com/do ...

  4. SQL Server数据库中表的增、删、改

    通过SqlCommand对象的ExecuteNonQuery方法执行命令行,来实现数据库中表的增.删.改.主要有5步 using System.Data.SqlClient;//载入数据库命名空间 p ...

  5. epoll ET(边缘触发) LT(水平触发)

    EPOLL事件有两种模型: Edge Triggered (ET) 边缘触发只有数据到来,才触发,不管缓存区中是否还有数据.Level Triggered (LT) 水平触发只要有数据都会触发. 首先 ...

  6. linux usb总线驱动(一)

    目录 linux usb总线驱动框架 USB 介绍 传输类型 控制器接口 2440接口 基本流程 alloc_dev choose_address hub_port_init usb_get_devi ...

  7. Makefile 使用总结(转)

    Makefile 使用总结  转自 https://www.cnblogs.com/wang_yb/p/3990952.html 1. Makefile 简介 Makefile 是和 make 命令一 ...

  8. Beamer中左边画图, 右边文字解释

    \begin{columns} \column{.4\textwidth} \begin{figure} \centering % Requires \usepackage{graphicx} \in ...

  9. fstat函数

    一.函数原型 #include<sys/stat.h> #include<unistd.h> int fstat(int fildes,struct stat *buf); 返 ...

  10. Design Principles and Design Patterns

    设计原则解读. 设计原则是对设计模式的约束性要求,属于设计中基本的四项特征,不符合此四项特征的设计,不具有生命力. 设计模式也是在此四项设计原则上的具体化实例化衍生物. Martin原文: http: ...