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并发编程中select简单了解

    select可以监听channel的数据流动select的用法与switch语法非常类似,由select开始的一个新的选择块,每个选择条件由case语句来描述 与switch语句可以选择任何使用相等比 ...

  2. 面试题:JS中map的陷阱

    题目: ['2', '3', '4'].map(parseInt); 请说出上面代码的执行结果 错误回答: [2, 3, 4] 真正答案: [2, NaN, NaN] 解析: 因为 map 的算子是有 ...

  3. Font-Spider 一个神奇的网页中文字体工具,就是这么任性

    文章摘要:    1>>  font-spider 字体神奇 由于活动项目推广的需要,页面需要用到一些漂亮好看的字体,example : 邯郸-韩鹏毛遂体.ttf. 方正喵呜.ttf 我看 ...

  4. golang BDD testcase framework.

    BDD What is Behaviour Driven Development and why should I care? Behaviour Driven Development (BDD) i ...

  5. 经典算法分析:n^2与nlgn

    冒泡.插入.选择排序的时间复杂度为O(n2) Arrays.sort()时间复杂度为nlgn 具体算法实现代码: package recursion; import java.util.Arrays; ...

  6. CentOS6.8下安装mysql

    转自https://blog.csdn.net/jeffleo/article/details/53559712?utm_source=itdadao&utm_medium=referral ...

  7. 从Git上导入Maven 项目到Eclipse

    Note: 经验之谈,操作过程中有不懂的地方可以留言问. Step: Open the Eclipse: --1.File>>Import>>Git:Project from ...

  8. topcoder srm list

    300 305 310 315 320 325 330 335 340 350 360 370 380 390 400 410 415 420 425 430 435 440 445 450 455 ...

  9. uniGUI试用笔记(十)

    今天用LoadRunner对uniGUI的Standalone模式的程序进行了一次压力测试,程序采用三层模式,将应用服务器与Web服务器分离,由于条件限制,数据库.应用服务和Web服务都部署在同一条云 ...

  10. P2517 [HAOI2010]订货

    思路 费用流水题 对每月拆点,入点向出点连cap=ui的边,s向入点连cost=di的边,i的入点向i+1的入点连cap=S的边即可 代码 #include <cstdio> #inclu ...