数位DP

f[位数][自身模k余数][各位数字之和模k余数][当前位是否有上限]=方案数

k<10000,空间不够,如何优化?

不必优化,2^31以内,数字最多只有10位,各位数字之和最多为99(10个9),所以k>99时肯定无解。数组开到100+就可以了

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int f[][][];
int x[],cnt=;
int a,b,k;
inline void dv(int t){
cnt=;
while(t){x[++cnt]=t%;t/=;}
memset(f,-,sizeof f);
return;
}
int DP(int p,int m1,int m2,bool flag){
if(flag && f[p][m1][m2]>=)return f[p][m1][m2];
if(!p)return (!m1 && !m2);
int lim=flag?:x[p];
int res=;
for(int i=;i<=lim;i++)
res+=DP(p-,(m1*+i)%k,(m2+i)%k,flag||(i<lim));
if(flag)f[p][m1][m2]=res;
return res;
}
int main(){
int i,j;
int T=read();
while(T--){
scanf("%d%d%d",&a,&b,&k);
if(k>){printf("0\n");continue;}
dv(b);
int ans=DP(cnt,,,);
dv(a-);
ans-=DP(cnt,,,);
printf("%d\n",ans);
}
return ;
}

UVa11361 Investigating Div-Sum Property的更多相关文章

  1. UVA11361 Investigating Div-Sum Property(数位dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 题目意思:问在区间[A,B]有多少个数不仅满足自身是k的倍数,而且其各个位数上的和 ...

  2. Data Structure Binary Tree: Convert an arbitrary Binary Tree to a tree that holds Children Sum Property

    http://www.geeksforgeeks.org/convert-an-arbitrary-binary-tree-to-a-tree-that-holds-children-sum-prop ...

  3. Data Structure Binary Tree: Check for Children Sum Property in a Binary Tree

    http://www.geeksforgeeks.org/check-for-children-sum-property-in-a-binary-tree/ #include <iostream ...

  4. DOM概念的区分:Attribute和Property, html()及.text(), .val()

    Attribute就是dom节点自带的属性 例如:html中常用的id.class.title.align等: <div id="immooc" title="慕课 ...

  5. JavaScript动态设置div的样式的方法

    有时候需要根据需要动态设置div的样式,当然对于稍有经验的javascript开发者来说,这一切都是那么的简单,但是对于初学者或者说没有相关经验的开发者来说可能就是一个不大不小的难关,下面就通过实例简 ...

  6. Solr调研总结

    http://wiki.apache.org/solr/ Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍solr的功能使用及相关注意事项;主要包括以下内容:环境 ...

  7. solr教程,值得刚接触搜索开发人员一看

    http://blog.csdn.net/awj3584/article/details/16963525 Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍sol ...

  8. Solr总结

    http://www.cnblogs.com/guozk/p/3498831.html Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍solr的功能使用及相关注 ...

  9. 【转载】solr教程,值得刚接触搜索开发人员一看

    转载:http://blog.csdn.net/awj3584/article/details/16963525 Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍 ...

随机推荐

  1. [Codeforces Round #250]小朋友和二叉树

    题目描述: bzoj luogu 题解: 生成函数ntt. 显然这种二叉树应该暴力薅掉树根然后分裂成两棵子树. 所以$f(x)= \sum_{i \in c} \sum _{j=0}^{x-c} f( ...

  2. HTTP-常用配置

    前言 这篇主要介绍HTTP服务程序环境 可能有一些介绍不到,博主能力有限,欢迎大神来纠正改进 HTTP协议从http/0.9到如今的http/2.0中间发生了很大的改变,现在主流的事http/1.1 ...

  3. java实现可安装的exe程序

    java实现可安装的exe程序 通过编写Java代码,实现可安装的exe文件的一般思路: 1.在eclipse中创建java项目,然后编写Java代码,将编写好的Java项目导出一个.jar格式的ja ...

  4. OpenCV编译 Make出错 recipe for target 'modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/all' failed

    OpenCV编译  Make出错 recipe for target 'modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/all' failed 添 ...

  5. Python基础(三)—— print()格式化输出变量

    先举一个简单的例子说明: name = 'Jack' answer = input('你好,%s '%(name) + '你认识 Sean 不, 输入 yes or no\n') print('Sea ...

  6. 线段树:CDOJ1591-An easy problem A (RMQ算法和最简单的线段树模板)

    An easy problem A Time Limit: 1000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Pr ...

  7. 数学基础:HUD1124-Factorial(N!末尾0的个数)

    Factorial Problem Description The most important part of a GSM network is so called Base Transceiver ...

  8. poj 2376 选择工作区间问题 贪心算法

    题意:给一些工作区间,如何选取最小的工作数量,覆盖[1,T]的工作时长 一开始的思路,当然也是错误的思路: 我想着,最小工作数量是吧?那肯定就是选择结束时间最晚的,给结束时间来一个排序.哎这个思路错误 ...

  9. TypeError: cannot use a string pattern on a bytes-like object

    一劳永逸解决:TypeError: cannot use a string pattern on a bytes-like object TypeError: cannot use a string ...

  10. STM8 EEPROM心得

    对于STM8来说,其内部的EEPROM确实是个不错的东西,而且STM8S103/105价格已经非常便宜了,当然也可以用STM8S003/005代替,而且价格更便宜,大概在,1.2/2.0元左右,比10 ...