题意:求一个区间内满足所有数位不同数字个数小于K的数字总和。比如:k=2   1,2,3所有数位的不同数字的个数为1满足,但是123数位上有三个不同的数字,即123不满足。

我们可以使用一个二进制的数字来记录某个数字是否已经出现,0为还没有出现,1表示该数字已经出现了。这里还需要注意前导零的干扰。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#include<string>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
#define ri register int
typedef long long ll; inline ll gcd(ll i,ll j){
return j==0?i:gcd(j,i%j);
}
inline ll lcm(ll i,ll j){
return i/gcd(i,j)*j;
}
inline void output(int x){
if(x==0){putchar(48);return;}
int len=0,dg[20];
while(x>0){dg[++len]=x%10;x/=10;}
for(int i=len;i>=1;i--)putchar(dg[i]+48);
}
inline void read(int &x){
char ch=x=0;
int f=1;
while(!isdigit(ch)){
ch=getchar();
if(ch=='-'){
f=-1;
}
}
while(isdigit(ch))
x=x*10+ch-'0',ch=getchar();
x=x*f;
}
struct st{
ll num;
ll sum;
st():num(0),sum(0){
}
st(ll num,ll sum):num(num),sum(sum){
}
}dp[20][2000];
int maxs;
int a[20];
const ll mod=998244353;
int change(int n){
int cnt=0;
while(n){
if(n&1)cnt++;
n/=2;
}
return cnt;
}
st dfs(int pos,int sta,int pre,bool limit){
if(pos==-1){
// cout<<pre<<endl; if(change(sta)<=maxs)
return st(1,0);
return st(0,0);
}
if(dp[pos][sta].num!=0&&!limit){
// printf("%d %lld\n",pos,dp[pos][sta].sum);
return dp[pos][sta];
}
int up=limit?a[pos]:9;
st ans; for(int i=0;i<=up;i++){
st tem;
if(change(sta|(int)pow(2,i))>maxs)
continue;
if(pre==0&&i==0){
tem=dfs(pos-1,sta,0,i==up&&limit);
}
else{
tem=dfs(pos-1,((int)pow(2,i))|sta,i,i==up&&limit);
}
ans.num+=tem.num;
ans.num=ans.num%mod;
ans.sum=(ans.sum+(ll)pow(10,pos)%mod*i*tem.num%mod+tem.sum)%mod;
}
if(!limit){
dp[pos][sta]=ans;
}
return ans;
}
ll solve(ll n){
int len=0;
while(n){
a[len++]=n%10;
n/=10;
}
return dfs(len-1,0,0,true).sum;
}
int main(){
ll l,r;
scanf("%lld%lld%d",&l,&r,&maxs);
printf("%lld",(solve(r)-solve(l-1)+mod)%mod);
return 0;
}

  

E. Segment Sum(数位dp)的更多相关文章

  1. Educational Codeforces Round 53 E. Segment Sum(数位DP)

    Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...

  2. zoj 3962 Seven Segment Display 数位dp

    非常好的一个题,可以比赛时想到的状态太奇葩,不方便转移,就一直没能AC. 思路:dp(i, j)表示已经考虑了前i位,前i位的和为j的贡献.如果当前的选择一直是最大的选择,那么就必须从0~下一位的最大 ...

  3. 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 ...

  4. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum (数位dp求和)

    题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的 ...

  5. Codeforces1073E Segment Sum 【数位DP】

    题目分析: 裸的数位DP,注意细节. #include<bits/stdc++.h> using namespace std; ; int k; ][],sz[][],cnt[][]; ] ...

  6. ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp

    Seven Segment Display Time Limit: 1 Second      Memory Limit: 65536 KB A seven segment display, or s ...

  7. ZOJ - 3962 - Seven Segment Display-17省赛-数位DP

    传送门:Seven Segment Display 题意:求一个给定区间每个数字的消耗值的和: 思路:数位DP,有点区间和的思想,还有就是这个十六进制,可以用%llx读,还是比较难的: 还有就是到最大 ...

  8. 数位DP:SPOJ KPSUM - The Sum

    KPSUM - The Sum One of your friends wrote numbers 1, 2, 3, ..., N on the sheet of paper. After that ...

  9. ZOJ 3962 Seven Segment Display(数位DP)题解

    题意:给一个16进制8位数,给定每个数字的贡献,问你贡献和. 思路:数位DP,想了很久用什么表示状态,看题解说用和就行,其他的都算是比较正常的数位DP. 代码: #include<iostrea ...

随机推荐

  1. 《DSP using MATLAB》Problem 7.12

    阻带衰减50dB,我们选Hamming窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  2. github/gitee使用办法

    github/gitee只要添加SSH公钥都是可以连接上的 比如把某个文件上传gitee 首先肯定要有权限    否则会一直提醒failed伤心心 接下来说常用语句 git config --list ...

  3. codeforces 804A Find Amir 思维/水题

    A few years ago Sajjad left his school and register to another one due to security reasons. Now he w ...

  4. H5入门须知

    ---恢复内容开始--- 首先,让我们来了解一下H5是做什么的,H5全称为“超文本标记语言”.是对网页进行编辑的技术.H5运用Hbulider进行网页编辑.网页可以分为三部分分别是title(主题)u ...

  5. c#泛型TryParse类型转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  6. 【SpringBoot】服务器端主动推送SSE技术讲解

    =====================16.高级篇幅之SpringBoot2.0服务器端主动推送SSE技术讲解 ============================ 1.服务端推送常用技术介绍 ...

  7. zabbix之 自动发现磁盘io util 监控

    一.iostat Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个.iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之 ...

  8. PPTV(pplive)_forap_1084_9993.exe 木马清除经历

    ## 流氓行经 这几天电脑上突然自动安装pptv,金山毒霸清除了也不管用, 卸载了pptv过一会又自动安装上了,太嚣张了哈. ## 监控进程跟目录变化 接下来使用 ProcessMonitor 监控进 ...

  9. Python的Django

    1   第一部分目录详解 修改django的项目当中的url中的配置: from django.contrib import admin from django.conf.urls import ur ...

  10. Ali流量控制中间件Sentinel

    原文链接: https://blog.csdn.net/u012190514/article/details/81383698 Sentinel 是什么 随着微服务的流行,服务和服务之间的稳定性变得越 ...