XJOI网上同步训练DAY5 T3
2024-10-04 00:24:31
就是对于一个数,我们去考虑把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 ;
}
最新文章
- Ubuntu 树莓派2b交叉编译环境
- sql 查询最近30分钟或者自定义时间数据
- DataTables 入门使用
- smartUpload组件批量下载
- HDU 3397 Sequence operation (区间合并,操作比较多)
- js共享onload事件
- 非阻塞connect
- Golang版protobuf编译
- oracle分组-神奇的cube和rollup
- Python面向对象篇(1)-类和对象
- Redis Cluster集群主从方案
- js基础和技巧记录
- centos7 开放3306端口并可以远程访问
- [工作相关] GS产品使用LInux下Oracle数据库以及ASM存储时的数据文件路径写法.
- skearn/pandas
- Luogu P1726 上白泽慧音
- css基础之line-height
- 遍历 SortedList<;string, string>; 中的值(可用于datatable转json)
- Swarm使用原生的overlay网络
- webform版部分视图与请求拦截
热门文章
- tigerVNC远程桌面,跨内网
- Android客户端实现七牛云存储文件上传
- Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数
- HDU-3665(单源最短路)
- Centos6 httpd与tomcat整合发布
- 简单Mysql思维导图
- ubantu14.04 apache2 支持重写模式
- 黑马程序员_<;<;泛型>;>;
- Java 将自己定义的对象作为HashMap的key
- LDAP 后缀操作