CF1073E Segment Sum
数位DP,求[L,R]区间内所有"数字内包含的不同数码不超过k个的数字"之和.在状态上加一维状态压缩表示含有的数码集合.一开始读错题以为是求数字的个数.读对题之后调了一会儿.
#include<cstdio>
typedef long long ll;
const int mod=998244353;
int cnt1[1024];
int f[20][1024],g[20][1024];
int F[20][1024],G[20][1024];
int p10[20];
void init(){
p10[0]=1;
for(int i=1;i<20;++i)p10[i]=p10[i-1]*10ll%mod;
cnt1[0]=0;
for(int i=1;i<1024;++i)cnt1[i]=cnt1[i>>1]+(i&1);
for(int i=0;i<10;++i)f[1][1<<i]=1,g[1][1<<i]=1,F[1][1<<i]=i,G[1][1<<i]=i;
g[0][0]=1;
for(int i=2;i<=18;++i){
for(int k=0;k<1024;++k){
for(int j=0;j<10;++j){
g[i][k|(1<<j)]=(g[i][k|(1<<j)]+g[i-1][k])%mod;
G[i][k|(1<<j)]=(G[i][k|(1<<j)]+G[i-1][k])%mod;
G[i][k|(1<<j)]=(G[i][k|(1<<j)]+g[i-1][k]*1ll*j%mod*p10[i-1]%mod)%mod;
}
for(int j=1;j<10;++j){
f[i][k|(1<<j)]=(f[i][k|(1<<j)]+g[i-1][k])%mod;
F[i][k|(1<<j)]=(F[i][k|(1<<j)]+G[i-1][k])%mod;
F[i][k|(1<<j)]=(F[i][k|(1<<j)]+g[i-1][k]*1ll*j%mod*p10[i-1]%mod)%mod;
}
}
}
}
int calc(ll lim,int c){//strictly less than lim
if(lim==(ll)(1e18)){
int ans=0;
for(int i=1;i<=18;++i){
for(int k=0;k<1024;++k){
if(cnt1[k]<=c)ans=(ans+F[i][k])%mod;
}
}
return ans;
}
int L[20],n=0;
while(lim){
L[++n]=lim%10;lim/=10;
}
int S=0;
int ans=0;
for(int i=1;i<=n-1;++i){
for(int k=0;k<1024;++k){
if(cnt1[k]<=c)ans=(ans+F[i][k])%mod;
}
}
int presum=0;
for(int i=n;i>=1;--i){
int lo=(i==n)?1:0;
for(int j=L[i]-1;j>=lo;--j){
int tmp=(1<<j)|S;
for(int k=0;k<1024;++k){
if(cnt1[tmp|k]<=c){
ans=(ans+g[i-1][k]*1ll*(presum*10ll+j)%mod*p10[i-1]%mod+G[i-1][k])%mod;
}
}
}
S|=(1<<L[i]);
presum=(presum*10ll+L[i])%mod;
}
return ans;
}
int main(){
init();
ll L,R;
int k;
scanf("%lld%lld%d",&L,&R,&k);
printf("%d\n",(calc(R+1,k)-calc(L,k)+mod)%mod);
return 0;
}
CF1073E Segment Sum的更多相关文章
- CF1073E Segment Sum 解题报告
CF1073E Segment Sum 题意翻译 给定\(K,L,R\),求\(L~R\)之间最多不包含超过\(K\)个数码的数的和. \(K\le 10,L,R\le 10^{18}\) 数位dp ...
- CF1073E Segment Sum 自闭了
CF1073E Segment Sum 题意翻译 给定\(K,L,R\),求\(L\)~\(R\)之间最多不包含超过\(K\)个数码的数的和. \(K<=10,L,R<=1e18\) 我 ...
- Codeforces 1073 E - Segment Sum
E - Segment Sum 思路: 数位dp 我们平时做的数位dp都是求满足条件的数的个数, 这里要求满足条件的数的和 只要在原来的基础上求每一位的贡献就可以了,所以传参数时要传两个 代码: #p ...
- Educational Codeforces Round 53 E. Segment Sum(数位DP)
Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...
- CodeForces - 1073E :Segment Sum (数位DP)
You are given two integers l l and r r (l≤r l≤r ). Your task is to calculate the sum of numbers from ...
- E. Segment Sum(数位dp)
题意:求一个区间内满足所有数位不同数字个数小于K的数字总和.比如:k=2 1,2,3所有数位的不同数字的个数为1满足,但是123数位上有三个不同的数字,即123不满足. 我们可以使用一个二进制的数 ...
- Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum
https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k ...
- CF 1073 E. Segment Sum
https://codeforces.com/problemset/problem/1073/E 题意:[l,r]中,出现0—9数字的种类数不超过k的数的和 dp[i][j][0/1] 表示 dfs到 ...
- Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum (数位dp求和)
题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的 ...
随机推荐
- easyui combotree combobox 使用例子
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...
- jqgrid 设置隔行换色
有时,为美观效应,需要设置jqgrid隔行换色.jqgrid提供altRows属性来配置 启动隔行换色:altRows: true,//隔行换色 $("#filterGrid"). ...
- easyui的datagrid
datagrid数据的绑定方式: 1)data 后跟数据行的json串 2)url 后跟{"total":,"rows":,"foot":} ...
- [浅谈CSS核心概念] CSS布局模型:float和position
1.流动模型 HTML元素在默认情况下都是按照"流动模型"进行布局的,网上也有人称之为"普通流"."文档流"之类的.这种布局模式的特点在于: ...
- 【转】MySQL执行计划分析
原文:http://www.cnblogs.com/wangyanhong/archive/2013/09/18/3327919.html 一.语法explain <sql语句>例如: e ...
- ZOJ3623:Battle Ships(全然背包)
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...
- Scala--特质
一.为什么没有多重继承 c++允许多重继承 Java不允许多重继承,类只能继承一个超类,可以实现任意数量的接口. 如何继承这两个抽象基类? Scala提供“特质”而非接口:特质可以同时抽象方法和具体方 ...
- 【转】CentOS 5 上安装git
转自 http://www.cnblogs.com/Neddy/archive/2011/02/28/1967548.html 注意安装的时候 都要以root身份 //先安装git依赖的包 yum i ...
- 汇编 EBP ,ESP 寄存器
知识点: CALL框架 EBP寄存器 栈底指针 ESP寄存器 栈顶指针 一.EBP栈底指针 EBP是一个特殊的寄存器,通过EBP+偏移量 可以访问CALL里边的局部变量.它的低16位叫BP ...
- CF891C Envy
题面 题解 首先要知道两个性质: 对于任意权值,最小生成树上该权值的边数是相同的. 对于任意一个最小生成树,当加完所有权值小于一个任意值的边之后,当前图的连通性是一样的. 于是我们按照权值分开处理,对 ...