[CodeForces 55D] Beautiful numbers && 数位DP
来源:互联网 发布:手机淘宝女款鞋子 编辑:程序博客网 时间:2024/05/07 17:40
凡是大于3维的状态我都莫名的想用记忆化省去一维 写法一样
注意要离散化LCM值 不然数组开不下 而且CF还报一个奇怪的错 看了我好久
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>using namespace std;typedef long long LL;const int MAXL = 2520;const int MAXN = 30;LL d[MAXN+10][MAXL+10][60];int bit[MAXN+10], Num[MAXL+10], Goback[MAXL+10], cnt;int gcd(int x, int y){while(y){int r = x % y;x = y;y = r;}return x;}LL dp(int h, int sum, int lcm, bool limit){if(h == 0) return (sum % Num[lcm]) ? 0 : 1;if(d[h][sum][lcm] != -1 && !limit) return d[h][sum][lcm];lcm = Num[lcm];LL ans = 0;int ed = limit ? bit[h] : 9;for(int i = 0; i <= ed; i++){int Newlcm;if(i == 0) Newlcm = lcm;else Newlcm = lcm / gcd(lcm, i) * i;ans += dp(h-1, (sum * 10 + i) % MAXL, Goback[Newlcm], limit && i == ed);}if(!limit) d[h][sum][Goback[lcm]] = ans;return ans;}LL solve(LL X){int Len = 0;memset(bit, 0, sizeof(bit));while(X) {bit[++Len] = X % 10;X /= 10;}return dp(Len, 0, 1, 1);}void init(){cnt = 0;memset(d, -1, sizeof(d));for(int i = 1; i <= MAXL; i++)if(!(MAXL % i))Num[++cnt] = i, Goback[i] = cnt;}int main(){init();int T; scanf("%d", &T); while(T--) {LL L, R;cin >> L >> R;LL ans = solve(R) - solve(L-1);cout << ans << '\n';}}
0 0
- Codeforces 55D Beautiful numbers 数位dp
- Codeforces 55D Beautiful numbers --- 数位DP
- Codeforces 55D Beautiful numbers 数位dp
- 【codeforces】55D. Beautiful numbers 数位DP
- [CodeForces 55D] Beautiful numbers && 数位DP
- Codeforces 55D Beautiful numbers 数位DP
- 【数位DP】 Codeforces 55D Beautiful numbers
- codeforces 55D Beautiful numbers[数位dp]
- [Codeforces 55D]Beautiful numbers(数位DP)
- CodeForces 55D Beautiful numbers (数位DP)
- Codeforces 55D Beautiful numbers【数位dp】
- codeforces 55D. Beautiful numbers (数位dp)
- CodeForces 55D Beautiful numbers(数位dp)
- codeforces-55D-Beautiful numbers(数位DP)
- codeforces 55D Beautiful numbers 数位dp
- Codeforces 55D Beautiful numbers 数位DP
- CodeForces 55D Beautiful numbers 数位dp
- codeforces 55D D. Beautiful numbers(数位dp+数论)
- unity3d--角色控制器和射线
- 二进制十进制互转---不能忘记的基础知识
- Linux 学习笔记
- Phoebe implementation invitational for 2014 tiro 3.0 部分题解
- Java线程(五)-线程的同步与锁
- [CodeForces 55D] Beautiful numbers && 数位DP
- Unity 碰撞检测和射线
- linux C中调用shell命令和运行shell脚本
- 吼吼
- Java解析JSON格式数据三
- HDU - 2526 - 浪漫手机 (字符串!!)
- 通俗的说OpenGL画图原理
- [UVA1636] Headshot && 概率
- 授予 SELECT ANY TABLE 权限后无法访问sys 用户的表