[HDU_3652]B-number
题目描述
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.
输入
输出
样例输入
13
100
200
1000
样例输出
1
1
2
2 求小于n是13的倍数且含有“13”的数的个数,有多组数据,输入到结束。 dp[i][j][k][l]。i表示i位数j表示第i位是j的k表示是否包含13(k==0 or 1)L表示膜13是l的数的个数
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int dp[][][][];
int e[];
void init()
{
e[]=;
for(int i=;i<=;i++)e[i]=(e[i-]*)%;
dp[][][][]=;
for(int i=;i<=;i++)
for(int j1=;j1<=;j1++)
for(int j2=;j2<=;j2++)
for(int l=;l<;l++)
{
int yu=(l-(j1*e[i-])%+)%;//yu表示dp[][][][l]从dp[][][][yu]转移//yu+j1贡献的余数=l
dp[i][j1][][l]+=dp[i-][j2][][yu];
if(j1==&&j2==)dp[i][j1][][l]+=dp[i-][j2][][yu];
else dp[i][j1][][l]+=dp[i-][j2][][yu];
}
}
int solve(int a)
{
int len=,ans=,mod=,d[];bool t=;
while(a)
{
d[++len]=a%;a/=;
}
d[len+]=;
for(;len>=;len--)
{
for(int i=;i<d[len];i++)
{
int yu=(-(mod*e[len])%)%;//算上高位mod13的余数还要加多少(yu)mod13才会得0
ans+=dp[len][i][][yu];
if(t||d[len+]==&&i==)ans+=dp[len][i][][yu];
}
if(d[len+]==&&d[len]==)t=;
mod=(mod*+d[len])%;
}
return ans;
}
int main()
{
int n;init();
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",solve(n+));
}
return ;
}
[HDU_3652]B-number的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- iOS---The maximum number of apps for free development profiles has been reached.
真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- [LeetCode] Number of Segments in a String 字符串中的分段数量
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
随机推荐
- 无序数组中第K大的数
1. 排序法 时间复杂度 O(nlogn) 2. 使用一个大小为K的数组arr保存前K个最大的元素 遍历原数组,遇到大于arr最小值的元素时候,使用插入排序方法,插入这个元素 时间复杂度,遍历是 O( ...
- Linux命令、权限
一.新建用户natasha,uid为1000,gid为555,备注信息为“master”: groupadd -g 555 natasha useradd -u 1000 -g 555 -c mast ...
- <jsp:param>传参乱码问题
在添加参数的界面添加<%request.setCharacterEncoding("UTF-8");%> 实例代码: login_confirm.jsp <%@ ...
- SQL Server无法连接到数据库
连接数据库的时候出现如下错误: 我解决的使用方法: 第一步:关闭上面的错误,取消连接数据库. 第二步:开始->程序->Microsoft SQL Server 2008 R2->配置 ...
- CodeIgniter学习笔记三:扩展CI的控制器、模型
一.扩展CI中的控制器 有时需要对CI中的控制器作统一操作,如进行登录和权限验证,这时就可以通过扩展CI控制器来实现. 扩展CI控制器只需要在application/core文件夹中建一个继承自CI_ ...
- cookie不能删除
cookie不仅仅包含一个键值对,还包含域 domain 路径path, 一般domain是请求的地址 www.baidu.com/news.html 那domain就是www.baidu.com ...
- python代码简写(推导式 if else for in)
c = a if a>b else b //如果a>b返回a,否则返回b >>> a = 1 >>> b = 2 >>> c = ...
- http协议--留
1.http消息结构 *http客户端,即web浏览器,链接到服务器,向服务器发送一个http请求的目的 *http服务器,即web服务,接受请求,并向客户端发送http响应数据 http统一资源标识 ...
- vue 三目运算
:class="followed ? 'btn-success':'btn-secondary'"
- Python读写tap设备
#!/usr/bin/python import os import struct import fcntl import binascii TUNSETIFF = 0x400454ca IFF_TA ...