https://codeforces.com/contest/1143/problem/B
题解:数位DP
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
int a[N];
char str;
struct node{};
int shu[20], dp[20];
int dfs(int len, bool shangxian)
{
if (len == 0)
return 1;
if (!shangxian && dp[len]) //为什么要返回呢?可以画图理解当我们搜到3XXX时,程序运行到1XXX时就已经把3XXX之后的搜索完了,记忆化也是这个用意.
return dp[len];
int res= 0, maxx = (shangxian ? shu[len] : 9);
for (int i = 0; i <= maxx; i++)
{
if(i==0)
res=max(res,dfs(len - 1,shangxian && i == maxx)); //只有之前有限制现在的达到了上限才能构成限制
else
res=max(res,i*dfs(len - 1,shangxian && i == maxx));
}
return shangxian ? res: dp[len] = res; //如果有限制,那么就不能记忆化,否则记忆的是个错误的数.
}
int solve(int x)
{
memset(shu, 0, sizeof(shu));
int k = 0;
while (x)
{
shu[++k] = x % 10; //保存a,b的数
x /= 10;
}
return dfs(k, true);
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
//scanf("%d",&t);
//while(t--){
scanf("%d",&n);
cout<<solve(n)<<endl;
//}
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Hello world!" << endl;
return 0;
}