题目大意:
  若一个十进制数$x$(不含前导零)满足数码$i$恰好出现$t_i$次,则这个数是坏的,否则是好的。求区间$[L,R](1\le L,R\le10^{18})$中有多少好数。

思路:
  显然可以将区间$[L,R]$拆成$[1,R],[1,L)$分别计算。考虑计算区间$[1,n]$中好数的个数,可以用类似数位DP的方法,对于长度与$n$相等的情况枚举与$n$的LCP和LCP前的数字,否则枚举长度及首位数字直接计算。当限制不存在时,显然可以通过组合数计算答案。加上限制可以用容斥来计算,极限数据时间复杂度约$O(2^{10}\cdot18\cdot10\cdot18)$。

 #include<cstdio>
#include<cctype>
typedef long long int64;
inline int64 getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int64 x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int B=,M=;
int t[B],tmp[B],dig[M],spc[B];
int64 C[M][M],pow[B+][M];
inline int64 calc(int l) {
int64 ret=;
for(register int i=;i<=spc[]&&l>=;i++) {
if(tmp[spc[i]]<) return ;
ret*=C[l][tmp[spc[i]]];
l-=tmp[spc[i]];
}
ret*=pow[-spc[]][l];
return ret;
}
inline int64 count() {
int64 ret=;
for(register int i=;i<B;i++) tmp[i]=t[i];
for(register int i=;i<=dig[]-;i++) {
for(register int j=;j<B;j++) {
tmp[j]--;
ret+=calc(i-);
tmp[j]++;
}
}
for(register int i=dig[];i;i--) {
for(register int j=i==dig[];j<dig[i];j++) {
tmp[j]--;
ret+=calc(i-);
tmp[j]++;
}
tmp[dig[i]]--;
}
ret+=calc();
return ret;
}
inline int64 solve(int64 n) {
if(!n) return ;
for(dig[]=;n;n/=) dig[++dig[]]=n%;
int64 ret=;
for(register int i=;i<<<B;i++) {
for(register int j=spc[]=;j<B;j++) {
if((i>>j)&) spc[++spc[]]=j;
}
ret+=(__builtin_popcount(i)&?-:)*count();
}
return ret;
}
inline void init() {
for(register int i=;i<M;i++) {
for(register int j=C[i][]=;j<=i;j++) {
C[i][j]=C[i-][j-]+C[i-][j];
}
}
for(register int i=;i<=B;i++) {
for(register int j=pow[i][]=;j<M;j++) {
pow[i][j]=pow[i][j-]*i;
}
}
}
int main() {
init();
for(register int T=getint();T;T--) {
const int64 l=getint(),r=getint();
for(register int i=;i<B;i++) t[i]=getint();
printf("%lld\n",solve(r)-solve(l-));
}
return ;
}

[CodeChef-DGTCNT]Chef and Digits的更多相关文章

  1. [Codechef CHSTR] Chef and String - 后缀数组

    [Codechef CHSTR] Chef and String Description 每次询问 \(S\) 的子串中,选出 \(k\) 个相同子串的方案有多少种. Solution 本题要求不是很 ...

  2. 【Codechef】Chef and Bike(二维多项式插值)

    something wrong with my new blog! I can't type matrixs so I come back. qwq 题目:https://www.codechef.c ...

  3. 【CodeChef】Chef and Graph Queries

    Portal --> CC Chef and Graph Queries Solution 快乐数据结构题(然而好像有十分优秀的莫队+可撤销并查集搞法qwq) 首先考虑一种方式来方便一点地..计 ...

  4. [CodeChef - GERALD07 ] Chef and Graph Queries

    Read problems statements in Mandarin Chineseand Russian. Problem Statement Chef has a undirected gra ...

  5. CodeChef CHEFSOC2 Chef and Big Soccer 水dp

    Chef and Big Soccer   Problem code: CHEFSOC2 Tweet     ALL SUBMISSIONS All submissions for this prob ...

  6. Codechef FNCS Chef and Churu

    Disciption Chef has recently learnt Function and Addition. He is too exited to teach this to his fri ...

  7. CodeChef - FNCS Chef and Churu(分块)

    https://vjudge.net/problem/CodeChef-FNCS 题意: 思路: 用分块的方法,对每个函数进行分块,计算出该分块里每个数的个数,这样的话也就能很方便的计算出这个分块里所 ...

  8. 【xsy2111】 【CODECHEF】Chef and Churus 分块+树状数组

    题目大意:给你一个长度为$n$的数列$a_i$,定义$f_i=\sum_{j=l_i}^{r_i} num_j$. 有$m$个操作: 操作1:询问一个区间$l,r$请你求出$\sum_{i=l}^{r ...

  9. codechef T2 Chef and Sign Sequences

    CHEFSIGN: 大厨与符号序列题目描述 大厨昨天捡到了一个奇怪的字符串 s,这是一个仅包含‘<’.‘=’和‘>’三种比较符号的字符串. 记字符串长度为 N,大厨想要在字符串的开头.结尾 ...

  10. CodeChef - UASEQ Chef and sequence

    Read problems statements in Mandarin Chinese and Russian. You are given an array that consists of n ...

随机推荐

  1. bzoj 3720 Gty的妹子树 树分块?瞎搞

    Gty的妹子树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2149  Solved: 781[Submit][Status][Discuss] D ...

  2. hive连接数

    使用hive分析日志作业很多的时候,需要修改mysql的默认连接数 修改方法   打开/etc/my.cnf文件 在[mysqld]  中添加 max_connections=1000 重启mysql ...

  3. transition(动画属性)

    CSS 过渡(transition)是通过定义元素从起点的状态和结束点的状态,在一定的时间区间内实现元素平滑地过渡或变化的一种补间动画机制.你可以让属性的改变过程持续一段时间,而不是立即生效. 通过t ...

  4. Java基础学习知识体系图

  5. Visual Studio Code 配置C/C++环境

    0. 前言 VS Code 是微软发布一款跨平台的源代码编辑器,其拥有强大的功能和丰富的扩展,使之能适合编写许多语言. 本文面向初学者(但不是纯小白),分享一点我配置C/C++的经验. 本文所有内容均 ...

  6. bzoj2161: 布娃娃

    Description 小时候的雨荨非常听话,是父母眼中的好孩子.在学校是老师的左右手,同学的好榜样.后来她成为艾利斯顿第二 代考神,这和小时候培养的良好素质是分不开的.雨荨的妈妈也为有这么一个懂事的 ...

  7. 使用state模块部署lamp架构

    install_httpd: pkg.installed: - name: httpd httpd_running: service.running: - name: httpd - enable: ...

  8. openlayers3中应用proj4js

    要在openlayers3中应用proj4js,需要在html中引用proj4js,然后在引用所需要的projection的js定义,如 http://epsg.io/21781-1753.js 然后 ...

  9. tyvj1048 田忌赛马

    描述     中国古代的历史故事“田忌赛马”是为大家所熟知的.话说齐王和田忌又要赛马了,他们各派出N匹马,每场比赛,输的一方将要给赢的一方200两黄金,如果是平局的话,双方都不必拿出钱.现在每匹马的速 ...

  10. Google Intern

    申请 事情应该从去年(2013)说起,好基友从百度离职跳到了Google,回学校打印本科成绩单,然后晚上在scuacm群里,结果Dr. zuo问我想去实习么,正好有学长可以内推. 于是乎写了简历,然后 ...