题目链接

这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的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. mxnet环境搭建随记

    安装mxnet还是遇到不少麻烦事,现在简单记一下,挖个坑,后续详细补充,打算写一下我的mxnet探索之旅. 更新: 具体安装mxnet,cuda,opencv过程已经补坑——点击进入 不知道为什么,在 ...

  2. tornado使用(Mac)

    安装需求 Tornado 在 Python 2.5, 2.6, 2.7 中都经过了测试.要使用 Tornado 的所有功能,你需要安装 PycURL (7.18.2 或更高版本) 以及 simplej ...

  3. 使用SOUI开发的界面集锦

    仿QQ管家界面

  4. 高质量C++[转]

    高质量C++/C编程指南 文件状态 [  ] 草稿文件 [√] 正式文件 [  ] 更改正式文件 文件标识: 当前版本: 1.0 作    者: 林锐 博士 完成日期: 2001年7月24日 版 本  ...

  5. loj 1038(dp求期望)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25915 题意:求一个数不断地除以他的因子,直到变成1的时候 除的次 ...

  6. Java学习随笔4:Java的IO操作

    1. IO流的作用是读写设备上的数据,如硬盘文件.内存.键盘.网络等.根据数据走向,可分为:输入流和输出流:根据处理的数据类型,可分为:字节流和字符流.字节流可以处理所有类型的数据,如MP3.图片.视 ...

  7. ++i与i++的区别

    1. ++i 和 i++,在单独使用时,就是 i=i+1. 2. a = ++i,相当于 i=i+1; a = i; (先i = i + 1,再使用i的值).也可以写成 i++; a=i 3. a = ...

  8. node.js整理 02文件操作-常用API

    NodeJS不仅能做网络编程,而且能够操作文件. 拷贝 小文件拷贝 var fs = require('fs'); function copy(src, dst) { fs.writeFileSync ...

  9. 点击不同按钮生成不同窗体到某个panel上面,类似Frame用法--不错

    //点击不同按钮生成不同页面加载到某个panel上面.procedure TMainForm.DemoButtonClick(Sender: TObject); var NewDemoClass: T ...

  10. Codeforces Round #334 (Div. 2)

    水 A - Uncowed Forces #include <bits/stdc++.h> using namespace std; typedef long long ll; const ...