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));
}
---恢复内容结束---
B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)的更多相关文章
- [题解] Codeforces Round #549 (Div. 2) B. Nirvana
Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...
- Codeforces Round #549 (Div. 1)
今天试图用typora写题解 真开心 参考 你会发现有很多都是参考的..zblzbl Codeforces Round #549 (Div. 1) 最近脑子不行啦 需要cf来缓解一下 A. The B ...
- 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 ...
- Codeforces Round #549 (Div. 2) 训练实录 (5/6)
The Doors +0 找出输入的01数列里,0或者1先出完的的下标. Nirvana +3 输入n,求1到n的数字,哪个数逐位相乘的积最大,输出最大积. 思路是按位比较,从低到高,依次把小位换成全 ...
- CodeForces Round #549 Div.2
A. The Doors 代码: #include <bits/stdc++.h> using namespace std; ; int N; , One = ; int a[maxn], ...
- [ 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 ...
- Codeforces Round #549 (Div. 2) Solution
传送门 A.The Doors 看懂题目就会写的题 给一个 $01$ 序列,找到最早的位置使得 $0$ 或 $1$ 已经全部出现 #include<iostream> #include&l ...
- Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)
https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y ...
- Codeforces Round #549 (Div. 2) E 倍增处理按排列顺序的上一个位置
https://codeforces.com/contest/1143/problem/E 题意 p为n的一个排列,给出有m个数字的数组a,q次询问,每次询问a数组区间[l,r]中是否存在子序列为p的 ...
随机推荐
- MT【318】分式不等式双代换
已知$a,b>0$且$\dfrac{1}{a}+\dfrac{1}{b}=\dfrac{2}{3}$,求$\dfrac{1}{a-1}+\dfrac{4}{b-1}$的最小值. 解:令$m=\d ...
- 初识并发编程 MPI
MPI是一个跨语言的通讯协议,用于并发编程.MPI标准定义了一组具有可移植性的编程接口. 安装环境 MPICH 是开源的消息传递接口(MPI)标准的实现. 下载地址 # 解压文件 tar -xzvf ...
- 动态SQL之、条件判断(转)
错误方式一: 在mybatis的动态sql语句中使用<if>标签可以判断sql中的条件是否成立. <select id="getPerson" resultTyp ...
- (二分查找 结构体) leetcode33. Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...
- openstack项目【day23】:KVM介绍
阅读目录 什么是kvm 为何要用kvm kvm的功能 常见虚拟化模式 KVM架构 KVM工具集合 一 什么是kvm KVM 全称 Kernel-Based Virtual Machine.也就是说 K ...
- kubernetes云平台管理实战:deployment通过标签管理pod(十)
一.kubectl run命令拓展 1.RC创建 [root@k8s-master ~]# kubectl run web --generator=run/v1 --image=10.0.128.0: ...
- Mybatis-generator自动生成器
目录 前言牢骚 Mybatis-generator是什么? Mybatis-generator怎么使用? 第一步,Maven文件引用 第二步,数据库建立 第三步,写mybatis-generator. ...
- flyway和liquibase的使用样例
在代码上我们有svn和git等诸多的版本控制方法. 但是在数据库上却没有相应的工具.一度导致多环境见的数据库同步难以维持. flyway和liquibase都是常见的数据库版本控制工具. flyway ...
- Android Studio生成签名文件,自动签名,以及获取SHA1和MD5值
转载请标明出处:http://blog.csdn.net/donkor_/article/details/53487133 前言: 作为谷歌在2013年为开发者提供的IDE环境工具Android St ...
- SQLserver 数据库高版本无法还原到低版本的数据解决方法
sql server 数据库的版本只支持从上往下兼容.即高版本可以兼容低版本 .低版本不能兼容低版本.通常我们在开发时会用比较高的版本.但是部署到客户那边可能他们的数据库版本会比较低. 我们可以通过导 ...