hdoj3652 B-number
题意:给出n,问1-n中有13且能整除13的数数量。
就是hd3555和codeforces beautiful number的合成版。dp记录待填长度,是否带有13,前面数的模13余数,前一个数是k的时候的b-number数数量。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
const double EPS=1e-;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
int dp[][][][]; int dfs(int pos,int sum,int pre,int limit,string &str,int inc)
{
if(pos==str.size())return inc&&(sum%==);
if(!limit&&dp[str.size()-pos-][sum][pre][inc]!=-)return dp[str.size()-pos-][sum][pre][inc];
int up=limit?str[pos]-'':;
int res=;
for(int i=;i<=up;++i)
{
int nexsum=(sum*+i)%;
if(pre==&&i==)res+=dfs(pos+,nexsum,i,limit&&i==str[pos]-'',str,);
else res+=dfs(pos+,nexsum,i,limit&&i==str[pos]-'',str,inc);
//if(pos==1&&pre==1)cout<<i<<" "<<res<<" "<<endl;
}
if(!limit)dp[str.size()-pos-][sum][pre][inc]=res;
return res;
} int work(string &str)
{
return dfs(,,,,str,);
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
//lon casenum;
//cin>>casenum;
memset(dp,-,sizeof(dp));
//for(lon time=1;time<=casenum;++time)
string str;
for(lon time=;cin>>str;++time)
{
cout<<work(str)<<endl;
}
return ;
}
hdoj3652 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 ...
随机推荐
- web.xml+spring mvc基本配置
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=" ...
- php 截取字符串第一个字符,截取掉字符串最后一个字符的方法
php 截取字符串第一个字符,php截取掉字符串最后一个字符的方法: $frist = substr( $c_url, 0, 1 ); $delete_last = substr(base_url() ...
- DNS正反向区域解析(二)
域名查询工具 Nslookup命令 >server 202.106.0.20 #指定DNS服务器 >set q=A #指定要查询的类型(A,PTR,MX,CNAME,NS) >www ...
- ACM题目————STL练习之求次数
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...
- SNMP学习笔记之SNMP的安装及Python的调用
0x00 概述 本文是介绍SNMP在Windows和Linux(Ubuntu)下的安装,以及通过Python调用其接口的文章. 0x01 开发环境 Python 3.5.1 Windows 10 64 ...
- CP2102
1概述 CP2102其集成度高,内置USB2.0全速功能控制器.USB收发器.晶体振荡器.EEPROM及异步串行数据总线(UART),支持调制解调器全功能信号,无需任何外部的USB器件.CP2102与 ...
- Beetl模板引擎入门教程
最近项目中有个邮件发送的需求,不过要求发送的HTML格式的邮件.由于Beetl对java语言的良好支持和很好的性能,我们决定使用Beetl作为我们的模板引擎. Beetl官网已经有了很详细的教程,所以 ...
- Farey Sequence (素筛欧拉函数/水)题解
The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...
- 51NOD 1081 子段求和
1081 子段求和 给出一个长度为N的数组,进行Q次查询,查询从第i个元素开始长度为l的子段所有元素之和. 例如,1 3 7 9 -1,查询第2个元素开始长度为3的子段和,1 {3 7 9} ...
- 1、webpack编译打包Sass编译的css进js文件
cnpm install css-loader --save-dev //css-loader 是将css打包进js cnpm install style-loader --save-dev ...