题目链接

这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的von学长的blog,比着写了写,就是模版改改,不过状态转移构造不出,怎么着,都做不出来。

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL __int64
#define MOD 2520
LL dp[][][];
int index[];
int num[];
LL gcd(LL a,LL b)
{
return b == ?a:gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
return a*b/gcd(a,b);
}
LL dfs(int pos,int pre,int mod,int bound)
{
int end,tpre,tmod,i;
LL ans = ;
if(pos == -)
return pre%mod == ;
if(!bound&&dp[pos][pre][index[mod]] != -)
return dp[pos][pre][index[mod]];
end = bound ? num[pos] : ;
for(i = ;i <= end;i ++)
{
tpre = (pre* + i)%MOD;
if(i)
tmod = lcm(mod,i);
else
tmod = mod;
ans += dfs(pos-,tpre,tmod,bound&&i == end);
}
if(!bound)
dp[pos][pre][index[mod]] = ans;
return ans;
}
LL judge(LL x)
{
int pos = ;
while(x)
{
num[pos++] = x%;
x = x/;
}
return dfs(pos-,,,);
}
int main()
{
int t,i,num = ;
LL x,y;
memset(dp,-,sizeof(dp));
for(i = ;i <= MOD;i ++)
{
if(MOD%i == )
index[i] = num++;
}
cin>>t;
while(t--)
{
cin>>x>>y;
printf("%I64d\n",judge(y)-judge(x-));
}
return ;
}

CF 55D. Beautiful numbers(数位DP)的更多相关文章

  1. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  2. CodeForces - 55D - Beautiful numbers(数位DP,离散化)

    链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...

  3. CodeForces - 55D Beautiful numbers —— 数位DP

    题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...

  4. Codeforces - 55D Beautiful numbers (数位dp+数论)

    题意:求[L,R](1<=L<=R<=9e18)区间中所有能被自己数位上的非零数整除的数的个数 分析:丛数据量可以分析出是用数位dp求解,区间个数可以转化为sum(R)-sum(L- ...

  5. codeforces 55D. Beautiful numbers 数位dp

    题目链接 一个数, 他的所有位上的数都可以被这个数整除, 求出范围内满足条件的数的个数. dp[i][j][k], i表示第i位, j表示前几位的lcm是几, k表示这个数mod2520, 2520是 ...

  6. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  7. 【数位dp】CF 55D Beautiful numbers

    题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...

  8. CF 55D - Beautiful numbers(数位DP)

    题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...

  9. 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 ...

随机推荐

  1. 【翻译一】java-并发

    Lesson: Concurrency Computer users take it for granted that their systems can do more than one thing ...

  2. .NET NLog 详解(四) - filter

    我们将版本向前切换到20051025,这期的关注点是filter.我们在使用日志的时候可能希望加上一些过滤器,在满足某些特定条件的时候才输出.举个简单的使用方式如下: <nlog> < ...

  3. 手机访问 localhost

    为了测试开发的手机网站,常常需要使手机直接访问本地网络.在这个过程中碰到几个问题,记下来供以后参考 1. 在本地主机运行apache后,使用localhost和127.0.0.1可以访问页面,但使用I ...

  4. 【leetcode】plus One

    问题描述: Given a non-negative number represented as an array of digits, plus one to the number. The dig ...

  5. uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型 - 大总结,看完全明白了

    转自:http://blog.csdn.net/kiddy19850221/article/details/6655066 uint8_t / uint16_t / uint32_t /uint64_ ...

  6. 库函数系统调用文件方式,王明学learn

    库函数系统调用文件方式 基于C函数库的文件编程是独立于具体的操作系统平台的,不管是在Windows.Linux还是其他的操作系统中,都是使用这些函数.使用库函数进行程序设计可提高程序的可移植性. 对于 ...

  7. excel、csv、txt文件数据读取

    /// <summary> /// 读取Excel表每一行第一列的字符串集合 /// </summary> /// <param name="filePath& ...

  8. windows下mongodb安装与使用整理

    一.首先安装mongodb 1.下载地址:http://www.mongodb.org/downloads 2.解压缩到自己想要安装的目录,比如d:\mongodb 3.创建文件夹d:\mongodb ...

  9. JS Number对象

    数字属性 MAX_VALUE MIN_VALUE NEGATIVE_INFINITY POSITIVE_INFINITY NaN prototype constructor 数字方法 toExpone ...

  10. 【hdu3948-不同回文串的个数】后缀数组

    题意:求不同回文串的个数 n<=10^5 题解: 先按照manacher的构造方法改造一遍串,然后跑一遍manacher. 如ababa--> $#a#b#a#b#a#@ 然后跑一遍后缀数 ...