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 ...
随机推荐
- python 文件操作 练习:取得文件的最后存取时间
#coding=utf-8 import osimport time file_atime=int(os.path.getatime('d:\\a.txt'))print "file_ati ...
- SpringMVC中controller返回图片(转)
本文转自:http://blog.csdn.net/u011637069/article/details/51112187 SpringMVC中controller通过返回ModelAndView然后 ...
- iOS可执行文件__TEXT段限制 以及 Android 65K函数限制
1.先看下苹果关于 .ipa上传的大小规定: 最大构建版本文件大小 解压 XXX.ipa size Payload/xxx.app/xxx 32位 32位 + 64位 有些2dx.u3d游戏 或是 ...
- Django框架----基础
一个小问题: 什么是根目录:就是没有路径,只有域名..url(r'^$') 补充一张关于wsgiref模块的图片 一.MTV模型 Django的MTV分别代表: Model(模型):和数据库相关的,负 ...
- MySQL数据库----表与表之间的关系
表1 foreign key 表2 则表1的多条记录对应表2的一条记录,即多对一 利用foreign key的原理我们可以制作两张表的多对多,一对一关系 多对多: 表1的多条记录可以对应表2的一条记录 ...
- linux环境下安装jdk1.6
卸载rpm版的jdk: #rpm -qa|grep jdk 显示:jdk1.6.0_29-fcs 卸载:#rpm -e --nodeps jdk1.6.0_29-fcs 1.从sun公司网站www.s ...
- 编译安装vsftpd-3.0.2
编译安装vsftpd 首先下载源码包(我一般喜欢放在/home/test) 解压:tar -zxvf vsftpd-3.0.2.tar.gz 进入目录进行编译 cd vsftpd-3.0.2 编译之前 ...
- 关于编译安装php
之前也装过一次是nginx和php的, 这次也是... but, 不知道是不是版本的问题还是环境方面的影响, 导致之前的gd库是安装失败的, 所以上次安装zabbix也是失败的, 这次换了5.6.2版 ...
- Win32建立右键弹出菜单(PopMenu)
自定义右键菜单: #ifndef _CONTEXTMENU_H_ #define _CONTEXTMENU_H_ #include <windows.h> //动态菜单 #define I ...
- POJ2528 Mayor's posters(线段树&区间更新+离散化)题解
题意:给一个区间,表示这个区间贴了一张海报,后贴的会覆盖前面的,问最后能看到几张海报. 思路: 之前就不会离散化,先讲一下离散化:这里离散化的原理是:先把每个端点值都放到一个数组中并除重+排序,我们就 ...