hdu3652B-number(数位dp)
2024-10-01 02:27:24
B-number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6444 Accepted Submission(s):
3739
Problem Description
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.
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.
Input
Process till EOF. In each line, there is one positive
integer n(1 <= n <= 1000000000).
integer n(1 <= n <= 1000000000).
Output
Print each answer in a single line.
Sample Input
13
100
200
1000
100
200
1000
Sample Output
1
1
2
2
1
2
2
Author
wqb0039
Source
题意:找出1~n范围内含有13并且能被13整除的数字的个数
思路:http://blog.csdn.net/libin56842/article/details/10026063
#include<cstdio>
#include<iostream>
#include<cstring> using namespace std;
int dit[],f[][][]; int dfs(int pos,int mod,int have,int lim)
{
int num,ans,mod_x,have_x;
if(pos<=) return mod== && have==;
if(!lim && f[pos][mod][have]!=-) return f[pos][mod][have];
num=lim?dit[pos]:;ans=;
for(int i=;i<=num;i++)
{
mod_x=(mod*+i)%; have_x=have;
if(have== && i==) have_x=;
if(have== && i!=) have_x=;
if(have== && i==) have_x=;
ans+=dfs(pos-,mod_x,have_x,lim&&i==num);
}
if(!lim) f[pos][mod][have]=ans;
return ans;
} int main()
{
int n,len;
while(~scanf("%d",&n))
{
memset(dit,,sizeof dit);
memset(f,-,sizeof f);len=;
while(n)
{
dit[++len]=n%;
n/=;
}dit[len+]=;
printf("%d\n",dfs(len,,,));
}
return ;
}
最新文章
- 【转】 jquery遍历json数组方法
- Delphi 10.1 Berlin 官方未列之修正
- iOS--雪花掉落特效
- 第一天&hellip;&hellip;
- Fast Intro To Java Programming (1)
- Effective Java2读书笔记-创建和销毁对象(三)
- Navicat远程连接阿里云服务器的mysql
- Winform 实现跨线程以及Timer
- 一、PTA实验作业
- Matplotlib学习---matplotlib的一些基本用法
- Ubuntu下sublime-text3安装步骤
- 解决 login.live.com onedrive.live.com 等微软国外网站打不开问题
- [Python爬虫] 之三十一:Selenium +phantomjs 利用 pyquery抓取消费主张信息
- v-if和v-show的区别以及callback回调函数的体会
- 【EXCEL】SUMIF(条件を指定して数値を合計する)
- C#如何把日期转成YYYYMMDDHHMMSSFFF的精确到毫秒的格式?
- 关于\r和\n的一些问题总结
- AngularJs之HelloWorld
- STM32之VCP1/VCAP2引脚的处理
- POJ 1017 Packets(积累)
热门文章
- (转)分布式文件存储FastDFS(六)FastDFS多节点配置
- jmeter解决中文乱码问题
- 黑苹果开启retina,大分辨率的方法
- Typescript编译设置
- Git学习总结一(下载、初始化、添加文件)
- html 报告页面 v1.2 批量数据生成表格
- python第十二周:MySql
- 第三节:Web爬虫之BeautifulSoup解析库
- Excel 2010/2013/2016在鼠标右键新建xls或xlsx文件后,打开报错“无法打开文件”“文件格式或文件扩展名无效”
- py文件控制台执行时,报错:引入的模块不存在