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. Golang数组注意细节

    数组是多个相同类型数据的组合,一个数组一旦声明/定义了,其长度是固定的,不能动态变化. var arr[]int,这个arr就是slice切片. 数组中的元素可以是任何数据类型,包括值类型和引用类型, ...

  2. bzoj2152 / P2634 [国家集训队]聪聪可可(点分治)

    P2634 [国家集训队]聪聪可可 淀粉质点分治板子 边权直接 mod 3 直接点分治统计出所有的符合条件的点对再和总方案数约分 至于约分.....gcd搞搞就好辣 #include<iostr ...

  3. 简易DVD查询系统

    ==========DVD管理系统========== 这是DVD任务管理器的主界面: package day20181224; import java.text.ParseException; im ...

  4. Regsvr32 在64位机器上的用法(转载)

    转载:http://blog.csdn.net/xuzhimin1991/article/details/65436864 regsvr32是windows上注册 OLE 控件(DLL 或 Activ ...

  5. 牛客网数据库SQL实战(6-10)

    6.查找所有员工入职时候的薪水情况,给出emp_no以及salary, 并按照emp_no进行逆序CREATE TABLE `employees` (`emp_no` int(11) NOT NULL ...

  6. iOS开发 -------- 九宫格坐标计算

    一 要求 完成下面的布局 二 分析 寻找规律,每一个UIView的x坐标和y坐标 三 实现思路 (1) 明确每一块用得是什么View; (2) 明确每个View之间的父子关系,每个视图都只有一个父视图 ...

  7. memalign的作用【转】

    本文转载自:https://blog.csdn.net/lvwx369/article/details/41726415 转自:http://hi.baidu.com/narshben/item/ca ...

  8. win10+vscode部署java开发环境

    目录 Java开发插件配置: 调试: 快捷键: 启动配置文件launch.json: 启动配置说明: Launch: Attach: User Setting: 遇到的问题: 参考: Java开发插件 ...

  9. 【做题】cf603E——线段树分治

    首先感谢题解小哥,他在标算外又总结了三种做法. 此处仅提及最后一种做法. 首先考虑题目中要求的所有结点度数为奇数的限制. 对于每一个联通块,因为所有结点总度数是偶数,所以总结点数也必须是偶数的.即所有 ...

  10. Directional RNA-seq data -which parameters to choose?

    Directional RNA-seq data -which parameters to choose? REF: https://chipster.csc.fi/manual/library-ty ...