E - Segment Sum

思路:

数位dp

我们平时做的数位dp都是求满足条件的数的个数, 这里要求满足条件的数的和

只要在原来的基础上求每一位的贡献就可以了,所以传参数时要传两个

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int MOD = ;
int k;
pll dp[][];
int a[], tot;
LL pw[];
pll dfs(int pos, int s, bool zero, bool limit) {
if(!pos) return {__builtin_popcount(s) <= k, };
if(!limit && !zero && ~dp[pos][s].fi) return dp[pos][s];
int up = ;
if(limit) up = a[pos];
pll ans = {, };
for (int i = ; i <= up; i++) {
pll res;
if(zero && i == ) res = dfs(pos-, s, zero, limit&&i==up);
else res = dfs(pos-, s|(<<i), zero&&i==, limit&&i==up);
(ans.fi = ans.fi + res.fi) %= MOD;
(ans.se = ans.se + res.se + i*res.fi%MOD*pw[pos-]%MOD) %= MOD;
}
if(!limit && !zero) dp[pos][s] = ans;
return ans;
}
void init() {
pw[] = ;
for (int i = ; i < ; i++) pw[i] = (pw[i-] * ) % MOD;
for (int i = ; i < ; i++)
for (int j = ; j < ; j++) dp[i][j].fi = dp[i][j].se = -;
}
LL solve(LL n) {
tot = ;
init();
while(n) {
a[++tot] = n % ;
n /= ;
}
return dfs(tot, , , ).se; }
int main() {
LL l, r;
scanf("%lld %lld %d", &l, &r, &k);
printf("%lld\n", (solve(r) - solve(l-) + MOD) % MOD);
return ;
}

Codeforces 1073 E - Segment Sum的更多相关文章

  1. CF 1073 E. Segment Sum

    https://codeforces.com/problemset/problem/1073/E 题意:[l,r]中,出现0—9数字的种类数不超过k的数的和 dp[i][j][0/1] 表示 dfs到 ...

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

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

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

  4. CF1073E Segment Sum 解题报告

    CF1073E Segment Sum 题意翻译 给定\(K,L,R\),求\(L~R\)之间最多不包含超过\(K\)个数码的数的和. \(K\le 10,L,R\le 10^{18}\) 数位dp ...

  5. CF1073E Segment Sum 自闭了

    CF1073E Segment Sum 题意翻译 给定\(K,L,R\),求\(L\)~\(R\)之间最多不包含超过\(K\)个数码的数的和. \(K<=10,L,R<=1e18\) 我 ...

  6. Codeforces 963 A. Alternating Sum(快速幂,逆元)

    Codeforces 963 A. Alternating Sum 题目大意:给出一组长度为n+1且元素为1或者-1的数组S(0~n),数组每k个元素为一周期,保证n+1可以被k整除.给a和b,求对1 ...

  7. [Codeforces 280D]k-Maximum Subsequence Sum(线段树)

    [Codeforces 280D]k-Maximum Subsequence Sum(线段树) 题面 给出一个序列,序列里面的数有正有负,有两种操作 1.单点修改 2.区间查询,在区间中选出至多k个不 ...

  8. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum

    https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k ...

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

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

随机推荐

  1. win10常见问题处理办法

    1.当笔记本连接wifi时,提示,无internet,安全,而手机能正常连接wifi时: cmd(需管理员权限)执行命令 netsh winsock reset 出现已重置,重启电脑 解决方法 2.当 ...

  2. 一、初始PS软件

     PS的介绍 Adope Photoshop,简称“PS”,是由Adope Systems开发和发行的图像处理软件. Photoshop主要处理以像素所构成的数字图像,使用其众多的编修与绘图工具,可以 ...

  3. P1288 取数游戏II

    luogu原题 最近刚学了博弈论,拿来练练手qwq 其实和数值的大小并没有关系 我们用N/P态来表示必胜/必败状态 先在草稿纸上探究硬币♦在最左侧(其实左右侧是等价的)的一条长链的N/P态,设链长为n ...

  4. Android 4.4 根据uri获取路径的方法

    当我们选择图片以后,返回的是Uri,此时我们要把路径存储到数据库,必须将其转换成String类型. URI:  //content://com.android.providers.media.docu ...

  5. 对浏览器攻击:MS10-002

    对浏览器攻击:MS10-002 MS10-002漏洞介绍 针对微软Internet Explorer"极光"内存损坏的攻击,当用户查看特制网页时允许远程执行代码. 实践过程 命令行 ...

  6. Golang中使用kafka

    golang中比较好用的kafka client有 sarama confluent-kafka-go go_kafka_client optiopay-kafka siesta 其中 sarama的 ...

  7. Hunter’s Apprentice 【判断多边形边界曲线顺逆时针】

    问题 H: Hunter's Apprentice 时间限制: 1 Sec  内存限制: 128 MB 提交: 353  解决: 39 [提交] [状态] [命题人:admin] 题目描述 When ...

  8. php编程疑难解决-1

    全局变量和超全局变量 如果是php脚本script 或php代码, 一定要放在 php标签内<?php ?> 内. 这样apache才会把他当做php脚本内容来解析, 才会去调用php模块 ...

  9. 再谈fedora 23中的flash的安装

    安装下载, flash插件的地址是 https://get.adobe.com/flashplayer/ ls 的显示, 记住两个很常用的选项: 指定 "假设的屏幕的宽度" , - ...

  10. kubeadm 生成的token过期后,集群增加节点

    通过kubeadm初始化后,都会提供node加入的token: You should now deploy a pod network to the cluster. Run "kubect ...