题目大意:
  若一个十进制数$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. HDU 多校对抗赛 B Balanced Sequence

    Balanced Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. CSS中的@ AT规则

    大家可能在CSS中见到过字符@然后加一些关键字的用法,这种用法就称之为AT规则,在CSS中,种类还是很多的,这里总结列举下. 常规规则 所谓“常规规则”指的是语法类似下面的规则: @[KEYWORD] ...

  3. Spring任务调度<task:scheduled-tasks>【含cron参数详解】 (转载)

    Spring内部有一个task是Spring自带的一个设定时间自动任务调度 task使用的时候很方便,但是他能做的东西不如quartz那么的多! 可以使用注解和配置两种方式,配置的方式如下 引入Spr ...

  4. HDU2057

    http://acm.hdu.edu.cn/showproblem.php?pid=2057 涉及到16进制内的加法,可以用%I64x直接来处理,要注意到16进制中负数是用补码来表示的.一个比较困惑的 ...

  5. 【uva11468-Substring】AC自动机+dp

    http://acm.hust.edu.cn/vjudge/problem/31655 题意:给定k个模板串,n个字符以及选择它的概率pro[i],要构造一个长度问L的字符串s,问s不包含任意一个模板 ...

  6. 【CodeForces】841D. Leha and another game about graph(Codeforces Round #429 (Div. 2))

    [题意]给定n个点和m条无向边(有重边无自环),每个点有权值di=-1,0,1,要求仅保留一些边使得所有点i满足:di=-1或degree%2=di,输出任意方案. [算法]数学+搜索 [题解] 最关 ...

  7. NYOJ 115 城市平乱 (最短路)

    * 题目链接* 描述 南将军统领着N个部队,这N个部队分别驻扎在N个不同的城市. 他在用这N个部队维护着M个城市的治安,这M个城市分别编号从1到M. 现在,小工军师告诉南将军,第K号城市发生了暴乱,南 ...

  8. adt 运行时,显示no target selected.

    检查adt\adt-bundle-windows-x86-20131030\sdk\system-images下面是否有相关image文件.

  9. POJ2495(棋盘分治,染色)

    Incomplete chess boards Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2483   Accepted ...

  10. python学习笔记 async and await

    用asyncio提供的@asyncio.coroutine可以把一个generator标记为coroutine类型,然后在coroutine内部用yield from调用另一个coroutine实现异 ...