就是对于一个数,我们去考虑把t*****减到(t-1)9999*的代价。

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#define ll long long
typedef std::pair<ll,int> info;
std::map<info,info>mp;
ll p[],n;
ll read(){
ll t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
info calc(int idx,info x){
if (idx==){
if (x.first>=x.second) return info(,);
else return info(,x.first);
}
if (mp.find(x)!=mp.end()) return mp[x];
int t=x.first/p[idx-];
ll num=x.first-t*p[idx-];
info ans(,);
for (int i=t;i>;i--){
info res=calc(idx-,info(num,std::max(i,x.second)));
ans.first+=res.first+;
num=p[idx-]+res.second-std::max(i,x.second);
}
info res=calc(idx-,info(num,x.second));
ans.first+=res.first;ans.second+=res.second;
return mp[x]=ans;
}
int main(){
n=read();
p[]=;
for (int i=;i<=;i++) p[i]=p[i-]*;
int len=;
for (ll x=n;x;x/=) len++;
if (n==) puts("");
else printf("%lld\n",calc(len,info(n,)).first);
return ;
}

最新文章

  1. Ubuntu 树莓派2b交叉编译环境
  2. sql 查询最近30分钟或者自定义时间数据
  3. DataTables 入门使用
  4. smartUpload组件批量下载
  5. HDU 3397 Sequence operation (区间合并,操作比较多)
  6. js共享onload事件
  7. 非阻塞connect
  8. Golang版protobuf编译
  9. oracle分组-神奇的cube和rollup
  10. Python面向对象篇(1)-类和对象
  11. Redis Cluster集群主从方案
  12. js基础和技巧记录
  13. centos7 开放3306端口并可以远程访问
  14. [工作相关] GS产品使用LInux下Oracle数据库以及ASM存储时的数据文件路径写法.
  15. skearn/pandas
  16. Luogu P1726 上白泽慧音
  17. css基础之line-height
  18. 遍历 SortedList&lt;string, string&gt; 中的值(可用于datatable转json)
  19. Swarm使用原生的overlay网络
  20. webform版部分视图与请求拦截

热门文章

  1. tigerVNC远程桌面,跨内网
  2. Android客户端实现七牛云存储文件上传
  3. Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数
  4. HDU-3665(单源最短路)
  5. Centos6 httpd与tomcat整合发布
  6. 简单Mysql思维导图
  7. ubantu14.04 apache2 支持重写模式
  8. 黑马程序员_&lt;&lt;泛型&gt;&gt;
  9. Java 将自己定义的对象作为HashMap的key
  10. LDAP 后缀操作