题目大意:多个询问,每个询问问$[l,r](1\leqslant l\leqslant r\leqslant10^{18})$内有多少个数满足非零数位小于等于$3$。

题解:数位$DP$,$f_{i,j}$表示在第$i$位,有$j$个数位不是$0$的方案数

卡点:

C++ Code:

#include <cstdio>
#include <cstring>
int Tim, num[20];
long long M[5][20];
long long run(int x, int cnt, int lim) {
if (cnt > 3) return 0;
if (!x) return 1;
if ((~M[cnt][x]) && !lim) return M[cnt][x];
long long ans = 0;
for (int op = lim, i = lim ? num[x] : 9; ~i; i--, op = 0) {
ans += run(x - 1, cnt + bool(i), op);
}
if (!lim) M[cnt][x] = ans;
return ans;
}
long long solve(long long x) {
int len = 0;
while (x) {
num[++len] = x % 10;
x /= 10;
}
return run(len, 0, 1);
}
int main() {
scanf("%d", &Tim);
memset(M, -1, sizeof M);
while (Tim --> 0) {
long long l, r;
scanf("%lld%lld", &l, &r);
printf("%lld\n", solve(r) - solve(l - 1));
}
return 0;
}

  

[CF1036C]Classy Numbers的更多相关文章

  1. CF1036C Classy Numbers dfs+二分

    Classy Numbers time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...

  2. Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers

    C. Classy Numbers 题目链接:https://codeforces.com/contest/1036/problem/C 题意: 给出n个询问,每个询问给出Li,Ri,问在这个闭区间中 ...

  3. Codeforces 1036C Classy Numbers 【DFS】

    <题目链接> 题目大意: 对于那些各个位数上的非0数小于等于3的数,我们称为 classy number ,现在给你一个闭区间 [L,R]  (1≤L≤R≤1018).,问你这个区间内有多 ...

  4. Classy Numbers

    http://codeforces.com/group/w1oiqifZbS/contest/1036/problem/C ①先查找,存入vector(dfs)-->排序(sort)--> ...

  5. C. Classy Numbers

    链接 [http://codeforces.com/contest/1036/problem/C] 题意 给你l,r,让你找在这个闭区间内位数不为0不超过3的个数,1<=l,r<=1e18 ...

  6. 【Codeforces 1036C】Classy Numbers

    [链接] 我是链接,点我呀:) [题意] 让你求出只由3个非0数字组成的数字在[li,ri]这个区间里面有多少个. [题解] 只由3个非0数字组成的数字在1~10^18中只有60W个 dfs处理出来之 ...

  7. CF集萃1

    因为cf上一堆水题,每个单独开一篇博客感觉不太好,就直接放一起好了. CF1096D Easy Problem 给定字符串,每个位置删除要代价.求最小代价使之不含子序列"hard" ...

  8. nowcoder(牛客网)提高组模拟赛第一场 解题报告

    T1 中位数(二分) 这个题是一个二分(听说是上周atcoder beginner contest的D题???) 我们可以开一个数组b存a,sort然后二分b进行check(从后往前直接遍历check ...

  9. Educational Codeforces Round 50

    1036A - Function Height    20180907 \(ans=\left \lceil \frac{k}{n} \right \rceil\) #include<bits/ ...

随机推荐

  1. ios中的三种弹框

    目前为止,已经知道3种IOS弹框: 1.系统弹框-底部弹框 UIActionSheet  (1)用法:处理用户非常危险的操作,比如注销系统等 (2)举例: UIActionSheet *sheet = ...

  2. ES6初识-模块化

    export let A=123; export function test(){ console.log('test'); } export class Hello(){ test(){ conso ...

  3. 1060: [ZJOI2007]时态同步

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3610  Solved: 1521[Submit][Status][Discuss] Descript ...

  4. POJ1286 Necklace of Beads(Polya定理)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9359   Accepted: 3862 Description Beads ...

  5. spring-bean(xml方式管理)

    特点 每一次加载XML文件时候,都会将配置文件中包含的配置实例化. ID与name区别:name不是唯一的,但是可以使用特殊字符 Class:生成类的实例 Bean的作用域: 三种实例化方式 类的构造 ...

  6. ofbiz最新版13.07.01环境搭建、安装(linux环境下)

    一.软件必备: 1.jdk1.7 2.mysql5.6 3.安装tomcat 二.安装: 1.安装 JDK1.7 2.安装mysql数据库 3.下载apache-ofbiz-13.07.01.zip ...

  7. 【Mysql】给mysql配置远程登录

    grant all privileges on 库名.表名 to '用户名'@'IP地址' identified by '密码' with grant option; flush privileges ...

  8. 内置函数系列之 map

    map(映射函数)语法: map(函数,可迭代对象) 可以对可迭代对象中的每一个元素,分别执行函数里的操作 # 1.计算每个元素的平方 lst = [1,2,3,4,5] lst_new = map( ...

  9. JAVA 扫雷 程序

    文件列表 2.主程序入口 3.1部分源代码 package MineSweeper; import java.awt.BorderLayout; import java.awt.Font; impor ...

  10. JavaSE——javac、javap、jad

    一.javac 用法:javac <选项> <源文件> 其中,可能的选项包括: -help                            帮助信息   -g       ...