An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is divisibleby 3 and 12(3+7+0+2) is also divisible by 3. This property also holds for the integer 9.In this problem, we will investigate this property for…
题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的和(并且模998244353) 例如求区间[10,50],k=1,答案为ans=(11+22+33+44)%998244353=110. Examples input Copy 10 50 2 output Copy 1230 input Copy 1 2345 10 output Copy 275…
You are given two integers l l and r r (l≤r l≤r ). Your task is to calculate the sum of numbers from l l to r r (including l l and r r ) such that each number contains at most k k different digits, and print this sum modulo 998244353 998244353 . For…
题目分析: 裸的数位DP,注意细节. #include<bits/stdc++.h> using namespace std; ; int k; ][],sz[][],cnt[][]; ],hp[],num; int dfs(int now,int lst){ ) ; ; ;i<hp[now];i++){ ;j<(<<);j++){ &&i==?:(<<i)); int z = __builtin_popcount(j|pp|lst); if…
题意:求一个区间内满足所有数位不同数字个数小于K的数字总和.比如:k=2   1,2,3所有数位的不同数字的个数为1满足,但是123数位上有三个不同的数字,即123不满足. 我们可以使用一个二进制的数字来记录某个数字是否已经出现,0为还没有出现,1表示该数字已经出现了.这里还需要注意前导零的干扰. #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include…
Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0; for(int i = 1; i <= n; i ++)     ans += lowbit(i) lowbit(i)的意思是将i转化成二进制数之后,仅仅保留最低位的1及其后面的0,截断前面的内容,然后再转成10…
题目大意 给出整数k和t,需要产生一个满足以下要求的第k个十六进制数 即十六进制数每一位上的数出现的次数不超过t 首先我们先这样考虑,如果给你了0~f每个数字可以使用的次数num[i],如何求长度为L且满足要求的十六进制数有多少个 dp[i][l]表示使用了前i个数字,已经将L的空位填上了l个的数有多少个 转移方程 dp[i][l] = sigma(dp[i-1][l-j]*C[len-l+j[j]) 其中j是枚举填新的数的个数,C是组合数(选出j个空位填上新数) 有了这个dp后,现在的问题就变…
ACdreamOJ 1154 Lowbit Sum (数位dp) ACM 题目地址:pid=1154" target="_blank" style="color:rgb(0,136,204); text-decoration:none">ACdreamOJ 1154 题意: long long ans = 0; for(int i = 1; i <= n; i ++) ans += lowbit(i) lowbit(i)的意思是将i转化成二进制…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 题目意思:问在区间[A,B]有多少个数不仅满足自身是k的倍数,而且其各个位数上的和(十进制)也是k的倍数. 分析:数位dp 首先注意到1+9*9=82,即k最大只能是82,所以,在大于82是直接输出答案为0: dp[i][j][t]——表示从左往右递推到第i位时(后面所有位数用0填充),各个位数上的和mod k等于j,且这个数mod k等于t时的方案数 状态转移方程为dp[i][…
经典数位dp!而且这好像是数位dp的套路板子……不需要讨论原来我很头疼的一些边界. 改天用这个板子重做一下原来的一些数位dp题目. http://blog.csdn.net/the_useless/article/details/53674906 题目大意: 给定a,b,k三个正整数,统计在[a,b]之间的整数n中,有多少n自身是k的倍数,且n的各个数字(十进制)之和也是k的倍数.(1⩽a⩽b⩽231) 题目分析: 这是一道典型的数位DP题. n非常大,若是直接枚举的话会超时,考虑利用加法原理计…