Codeforces55D Beautiful numbers
原题链接
虽然依旧是套模板,但是因为我太弱了,不会建状态,所以去看了题解。。
这里就直接引用我看的题解吧,写的不错的。
题解
//我的代码
#include<cstdio>
#include<cstring>
using namespace std;
const int mod = 2520;
const int N = mod + 10;
typedef long long ll;
int a[20], lc[N], l;
ll f[20][N][50];
inline ll re()
{
ll x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
int gcd(int x, int y)
{
if (!y)
return x;
return gcd(y, x % y);
}
int LCM(int x, int y)
{
if (!y)
return x;
return x / gcd(x, y) * y;
}
ll dfs(int pos, int nw, int lcm, int lm)
{
if (pos < 0)
return nw % lcm ? 0 : 1;
if (!lm && f[pos][nw][lc[lcm]] > -1)
return f[pos][nw][lc[lcm]];
int i, k = lm ? a[pos] : 9;
ll s = 0;
for (i = 0; i <= k; i++)
s += dfs(pos - 1, (nw * 10 + i) % mod, LCM(lcm, i), lm && i == a[pos]);
if (!lm)
return f[pos][nw][lc[lcm]] = s;
return s;
}
ll calc(ll x)
{
int k = 0;
do
{
a[k++] = x % 10;
x /= 10;
} while (x > 0);
return dfs(k - 1, 0, 1, 1);
}
int main()
{
int i, t;
ll n, m;
for (i = 1; i * i <= mod; i++)
if (!(mod % i))
{
lc[mod / i] = ++l;
lc[i] = ++l;
}
memset(f, -1, sizeof(f));
t = re();
for (i = 1; i <= t; i++)
{
n = re();
m = re();
printf("%I64d\n", calc(m) - calc(n - 1));
}
return 0;
}
Codeforces55D Beautiful numbers的更多相关文章
- CodeForces - 55D Beautiful numbers —— 数位DP
题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...
- CodeForces - 55D - Beautiful numbers(数位DP,离散化)
链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...
- CodeForces 55D Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- CF 55D - Beautiful numbers(数位DP)
题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...
- Codeforces Beta Round #51 D. Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- ansj
Ansj中文分词使用教程 Ansj中文分词使用教程:https://blog.csdn.net/a822631129/article/details/52331202 ansj分词史上最详细教程:ht ...
- 三种方法让Response.Redirect在新窗口打开
通过设置form的target属性同样可以让Response.Rederect所指向的url在新的窗口打开,下面为大家介绍三种具体的实现方法 Response.Rederect在默认情况下是在本页跳转 ...
- 模块移除 命令rmmod 的实现
// rmmod.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include < ...
- NFS 网络文件系统制作
1. 构建根文件系统主要是建立相关的文件目录,以及各目录下相关的配置文件.管理工具等. 2. 首先创建文件目录. mkdir rootfs cd rootfs mkdir bin dev etc li ...
- orthodb
1.数据库 orthodb数据: odb10v0_levels.tab.gz: NCBI taxonomy nodes where Ortho DB orthologous groups (OGs) ...
- 02_数据库基础之(二)sql语句入门
1.基本增删改查操作 #一. 数据类型 常用的3中 # .字符串 例如:你的名字 我是中国人 在数据库中要使用 ‘’引起来 '苹果手机' # .整数类型 例如: 你的年龄 ,办公室的人数 个 ,直接使 ...
- VR/AR 科技了解
Dream学院学习资料: VR/AR科技学习需要先学习NDK技术 AR/VR->图像学->图像处理(OpenCV->Intel公司在1999年发布3.2).图像绘制渲染(OpenGL ...
- c++中的类(class)-----笔记(类模板)
1,一个模板类至少具有一个类参数,类参数是个符号以表示将要被某个确定数据类型代替的类型. #include<iostream> #include<string> using n ...
- Vue之常用语法
变量的定义: var定义的变量:只有全局作用域和函数作用域.有变量提升,先打印后定义变量不会报错,打印结果为undefined let定义的变量:没有变量提升 ——>有局 ...
- TOJ3112: 单词串串烧(回溯)
传送门(<--可以点击的) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 “单词串串烧”是一款拼词智力游戏,给定4*4的方格,随机取16个 ...