B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)
---恢复内容开始---
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.
The only input line contains the integer nn (1≤n≤2⋅109).
Print the maximum product of digits among all integers from 1 to n.
390
216
7
7
1000000000
387420489
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));
}
---恢复内容结束---
最新文章
- window 运行指令(1)
- maven No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
- C#中使用DLL文件
- GUI编程笔记(java)09:GUI控制文本框只能输入数字字符案例
- 版本控制-git的使用
- java实例变量及方法调用顺序
- perconaXTRADB Cluster在Redhat Linux上的安装
- boost库之geometry
- Python Fabric远程自动部署简介
- 3. VIM 系列 - 遇见你的第一个插件
- Navicat 连接VMware中Ubuntu 下的mysql5.7遇到的坑
- bat执行python脚本,执行多条命令
- .net core 2.0 Unable to convert MySQL date/time to System.DateTime
- 《JavaScript Dom 编程艺术》读书笔记-第6章
- 51nod 1092(lcs)回文字符串
- 【Python】进程间共享实例
- 《算法》第六章部分程序 part 2
- 【Java基础】JAVA不可变类(immutable)机制与String的不可变性
- zz VS2010配色方案
- C#中调用Dll动态链接库