UVa11361 Investigating Div-Sum Property
数位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的更多相关文章
- UVA11361 Investigating Div-Sum Property(数位dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 题目意思:问在区间[A,B]有多少个数不仅满足自身是k的倍数,而且其各个位数上的和 ...
- 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 ...
- 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 ...
- DOM概念的区分:Attribute和Property, html()及.text(), .val()
Attribute就是dom节点自带的属性 例如:html中常用的id.class.title.align等: <div id="immooc" title="慕课 ...
- JavaScript动态设置div的样式的方法
有时候需要根据需要动态设置div的样式,当然对于稍有经验的javascript开发者来说,这一切都是那么的简单,但是对于初学者或者说没有相关经验的开发者来说可能就是一个不大不小的难关,下面就通过实例简 ...
- Solr调研总结
http://wiki.apache.org/solr/ Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍solr的功能使用及相关注意事项;主要包括以下内容:环境 ...
- solr教程,值得刚接触搜索开发人员一看
http://blog.csdn.net/awj3584/article/details/16963525 Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍sol ...
- Solr总结
http://www.cnblogs.com/guozk/p/3498831.html Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍solr的功能使用及相关注 ...
- 【转载】solr教程,值得刚接触搜索开发人员一看
转载:http://blog.csdn.net/awj3584/article/details/16963525 Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍 ...
随机推荐
- java,求1-100之和。
package study01; public class TestWhile { public static void main(String[] args) { int sum = 0; int ...
- webservice基础
一.webservice概念 webservice用于异构平台之间的交互,我用Java写的程序,可以用php..net.pythod等其它语言的程序来访问我的接口.webservice有很多框架帮我们 ...
- Convert HTML Entities-freecodecamp算法题目
Convert HTML Entities 1.要求 将字符串中的字符 &.<.>." (双引号), 以及 ' (单引号)转换为它们对应的 HTML 实体. 2.思路 利 ...
- jenkins+maven+svn 自动化部署
背景: 公司的web平台使用JAVA写的,但是不是用Tomcat部署的,代码内部自带了Web服务器,所以只需要有JAVA环境,将代码打包上传,启动脚本就可以. 项目是根据pom.xml打包成的是.zi ...
- 小试nginx日志分析xlog
nginx配置: http { #...其他配置 log_format tpynormal '$remote_addr | [$time_local] | $host | "$request ...
- 【js】【vue】获取当前dom层
多层嵌套,$event.currentTarget 指当前点击层
- Relu的缺点
Relu不适合梯度过大的的输入 Relu是我们在训练网络时常用的激活函数之一(对我而言没有之一).然而最近发现Relu太脆弱了,经常由于输入的函数梯度过大导致网络参数更新后,神经元不再有激活功能.特别 ...
- 如何提高UDP的可靠性
TCP是通过确认机制和超时重传机制实现可靠传输 UDP UDP它不属于连接型协议,因而具有资源消耗小,处理速度快的优点,所以通常音频.视频和普通数据在传送时使用UDP较多,因为它们即使偶尔丢失一两个数 ...
- 并查集:POJ1182-食物链(并查集比较高端的应用)
食物链 Time Limit: 1000MS Memory Limit: 10000K Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C ...
- 素数筛选:HDU2710-Max Factor
Max Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...