题目大意:
  若一个十进制数$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. Git菜鸟

    1.git 和svn的差异 git和svn 最大的差异在于git是分布式的管理方式而svn是集中式的管理方式.如果不习惯用代码管理工具,可能比较难理解分布式管理和集中式管理的概念.下面介绍两种工具的工 ...

  2. 【bzoj1010-toy】斜率优化入门模板

    dsy1010: [HNOI2008]玩具装箱 [题目描述] 有n个数,分成连续的若干段,每段(假设从第j个到第i个组成一段)的分数为 (X-L)^2,X为j-i+Sigma(Ck) i<=k& ...

  3. [POJ1082&POJ2348&POJ1067&POJ2505&POJ1960]简单博弈题总结

    鉴于时间紧张...虽然知道博弈是个大课题但是花一个上午时间已经极限了... 希望省选过后再回过头来好好总结一遍吧. 接下来为了看着顺眼一点...还是按照难度顺序吧   POJ1082 一道最简单的博弈 ...

  4. 【洛谷 P1896】[SCOI2005]互不侵犯(状压dp)

    题目链接 题意:在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. 这是道状压\(DP\)好题啊.. ...

  5. KM算法讲解

    对于二分图,我们可以用匈牙利来求出来最大匹配,但是如果给定每条边一个权值,我们要求这张图的最大匹配最大(小)权,单纯的用匈牙利就没法解决了,当然用费用流也可以做,但是代码较长,在处理完全二分图的时候时 ...

  6. Local Authentication Using Challenge Response with Yubikey for CentOS 7

    Connect Yubikey  ,then initialize YubiKey slot 2: ykpersonalize -2 -ochal-resp -ochal-hmac -ohmac-lt ...

  7. Kali Linux中前十名的Wifi攻击工具

    无 线网络的攻与防一直是比较热门的话题,由于无线信号可以被一定范围内的任何人接收到(包括死黑阔),这样就给WIFI带来了安全隐患:路由器生产厂商和网 络服务供应商(ISPs)的配置大多是默认开启了WP ...

  8. js 触发LinkButton点击事件,执行后台方法

    页面 <asp:LinkButton ID="lbtButton" runat="server"  CssClass="lbtButton&qu ...

  9. CUDA核函数调用基础数学API的一个奇葩情况

    今天测试在核函数在GTX 950M上运行的情况,核函数中的pow竟然出不来结果...在网上查了一圈,说是要改成powf,结果确实就好了. 但是,奇怪的是,CUDA版本都是最新的8.0,之前在GT 72 ...

  10. iOS 动画整理

    序列帧动画 曾经项目里的一段源码: 1234567891011121314 UIImageView * activityImageView = [[UIImageView alloc] init];N ...