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 ...
随机推荐
- 处女座和小姐姐(三)-数位dp1.0
链接:https://ac.nowcoder.com/acm/contest/329/G来源:牛客网 题目描述 经过了选号和漫长的等待,处女座终于拿到了给小姐姐定制的手环,小姐姐看到以后直呼666! ...
- python3获得命令行输入的参数
外部直接执行python文件时,我们有时需要获得命令行的参数 获得命令行参数的两种方式 1.通过sys.argv sys.argv:获得一个参数列表,第一个值为文件名本身,通过sys.argv ...
- modal template
<div class="modal fade" id="tmp_order_modal" tabindex="-1" role=&qu ...
- js 事件阻止冒泡
参考 https://www.cnblogs.com/zhuzhenwei918/p/6139880.html event.stopPropagation();
- NDK环境搭建方法1
1.新建NdkDemo工程 2.新建NdkJniUtils类,在内部声明native方法 3.引用 4.build项目,生成NdkDemo\app\build\intermediates\classe ...
- Local Storage
HTML代码: <ul id="edit" contenteditable="true"> <li>修改我吧,然后刷新页面看看,^_^& ...
- 【转】iOS 自动化性能采集
前言 对于iOS总体生态是比较封闭的,相比Android没有像adb这种可以查看内存.cpu的命令.在日常做性能测试,需要借助xcode中instruments查看内存.cpu等数据. 但是借助i ...
- manipulate
manipulate - 必应词典 美[mə'nɪpjə.leɪt]英[mə'nɪpjʊleɪt] v.控制:摆布:(有技巧地)使用:巧妙地处理(问题等) 网络操纵:被操纵:被控体 变形第三人称单数: ...
- c++ sizeof,strlen, length
#include <map>#include <iostream>#include <algorithm>#include <functional>#i ...
- xadmin系列之单实例模式
先看下单实例的定义 python的模块实现单例模式是python语言特有的,python的模块天然就是单例的,因为python有个pyc文件,导入一次后,第二次导入直接从pyc中取数据了 这里我们主要 ...