题目大意:给出a,b,k,问说在[a,b]这个区间有多少n,满足n整除k,以及n的各个为上的数字之和也整除k。
解题思路:数位dp,dp[i][j][x]表示第i为的时候,n整除k余j,n(以及考虑到的位数)的各个位置上的数字之和整除k余x的情况总数,并且每次要计算上限的临界值。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 15;
const int M = 105;
int a, b, k, n, d[N];
int dp[N][M][M];
void cat(int u) {
n = 1;
memset(d, 0, sizeof(d));
while (u) {
d[n++] = u%10;
u /= 10;
}
for (int i = 1; i <= n/2; i++)
swap(d[i], d[n-i+1]);
}
int solve (int u) {
if (u == 0)
return 1;
cat(u);
memset(dp, 0, sizeof(dp));
int p = 0, q = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++) {
for (int t = 0; t <= k; t++) {
for (int x = 0; x < 10; x++)
dp[i][(j*10+x)%k][(t+x)%k] += dp[i-1][j][t];
}
}
for (int j = 0; j < d[i]; j++)
dp[i][(p*10+j)%k][(q + j)%k]++;
p = (p*10+d[i])%k;
q = (q+d[i])%k;
}
if (p == 0 && q == 0)
dp[n][0][0]++;
return dp[n][0][0];
}
int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d%d%d", &a, &b, &k);
if (k > 100)
printf("0\n");
else
printf("%d\n", solve(b) - solve(a-1));
}
return 0;
}
分享到:
相关推荐
1969-诺奖得主Granger-Investigating Causal Relations by Econometric Models and Cross-spectral Methods
Preface The introduction of the IBM Personal Computer in 1982 fostered a technology revolution that has changed the way the world does business. Prior to that historic milestone, several personal ...
Investigating Bi-Level Optimization for Learning and Vision from a Unified Perspective A Survey and Beyond.zip
Investigating Novice Programming Mistakes in Large-ScaleStudent DataAmjad Altadmri School of ComputingUniversity of Kent Canterbury, Kent, UK aa803@kent.ac.ukNeil C. C. Brown School of ...
基于matlab的dm仿真代码研究 OFDM 系统 信道估计 这部分研究了不同估计器基于均方误差 (MSE) 性能来估计和跟踪信道参数的效率。 模拟中使用的估计器是 LS ...估计器,并评估了它们在传输域中的性能。...
Packet Tracer 是由Cisco公司发布的一个辅助学习工具,为学习思科网络课程的初学者去设计、配置、排除网络故障提供了网络模拟环境。用户可以在软件的图形用户界面上直接使用拖曳方法建立网络拓扑,并可提供数据包在...
Investigating Bi-Level Optimization for Learning and Vision from a Unified Perspective A Survey and Beyond.pdf
数字货币深入研究,Investigating.Cryptocurrencies.2018.6.pdf
Big Data, Small Devices Investigating the Natural World Using Real-Time Data 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如...
Computer Forensics Investigating Wireless Networks
Representing entities and relations in an embedding space is a well-studied approach for machine learning on relational data. Existing approaches, however, primarily focus on improving accuracy and ...
Biophysical analysis of membrane proteins investigating structure and function Wiley-VCH. 2008
NULL 博文链接:https://codewins.iteye.com/blog/425356
Investigating Effects of Post-Selection Feedback for Acquiring Ultra-Small Targets on Touchscreen
Investigating neural feedback circuits using bi-directional Multi-step Granger Causality
Investigating the effect of rudder profile on 6DOF ship turning performance-2019.pdf
调查数据集-TMDB电影介绍对于最后的项目,您将进行自己的数据分析并创建一个文件以共享记录您的发现的文件。 您应该首先查看数据集并集思广益,使用它可以回答哪些问题。 然后,您应该使用pandas和NumPy回答您最感...
android系统嵌入广告的调查,有助于了解android如何嵌入广告,如何鉴别app是否被嵌入广告。
研究TMDB电影数据集在这个项目中,我将分析一个数据集,然后传达我对它的发现。 我将使用Python库NumPy,pandas和Matplotlib简化我的分析。 在这个项目中,我将经历数据分析过程,并了解所有内容如何融合在一起。...
通过研究输入输出关联矩阵研究六自由度并联机构的设计方法,岳义,韦宝琛,本文致力于研究正交结构六自由度并联机构的设计方法。通过研究并联机构驱动输入与动平台输出的关联关系,构建了驱动输入与动平台