题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3652

题解:先预处理([0,0][1,1],[2,2]....[0,9],[10, 19],[20,29]......[900000000, 1000000000]  区域中 有子串13 (用1表示)余数为0,1,2.。。12的个数。以及 无子串13(用0表示)余数为0,1,2,3.。。12 的个数。

四维数组dp【一共多少位数】【最高位的数】【是否含有子串13】【余数】 例如  dp[4][1][1][0] 表示 (【1000,2000))(四位, 最高位数为1), 子串中含有13, 且余数为0的个数。

dp[a][b][c][d]

当求a = 2时必须 a=1的元素都已知,例如 求[20, 29)中含有13, 余数为3的个数。 即 dp【2】【2】【0】【3】 ,由于 [20, 29)可看做 20 + x(0—9)。而20 % 13 = 7, 只需找余数为9. 则 sum( dp【1】【j】【0】【9】)(j= 0,1,2.。。。9)。

需注意的是 当b = 1 时, 由于在低一位上有3,  所以这种情况要分开求。

/***Good Luck***/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath>
#include <numeric> #define Zero(a) memset(a, 0, sizeof(a))
#define Neg(a) memset(a, -1, sizeof(a))
#define All(a) a.begin(), a.end()
#define PB push_back
#define inf 0x3f3f3f3f
#define inf2 0x7fffffffffffffff
#define ll long long
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
void get_val(int &a) {
int value = , s = ;
char c;
while ((c = getchar()) == ' ' || c == '\n');
if (c == '-') s = -s; else value = c - ;
while ((c = getchar()) >= '' && c <= '')
value = value * + c - ;
a = s * value;
}
const int maxn = ;
int dp[maxn][maxn][][maxn];
int n; void change1(int i, int j, int m) {
for (int k = ; k <= ; ++k)
for (int kk = ; kk <= ; ++kk) {
dp[i][j][][(kk - m + ) % ] += dp[i - ][][k][kk];
}
} void change2(int i, int m,int j, int jj) {
for (int k = ; k <= ; ++k)
for (int kk = ; kk <= ; ++kk) {
dp[i][j][k][(kk + m) % ] += dp[i - ][jj][k][kk];
}
}
void init() {
Zero(dp);
int w = , m;
dp[][][][] = ;
for (int i = ; i <= ; ++i) dp[][i][][i] = ;
for (int i = ; i <= ; ++i) {
for (int j = ; j <= ; ++j) { for (int jj = ; jj <= ; ++jj) {
m = (j * w) % ;
if (j == && jj == ) {
m = (jj * w / )% ;
change1(i, j, m);
} else
change2(i, m, j, jj);
}
}
w *= ;
}
} int cal(int n1) {
if (n1 == ) return ;
char ch[];
Zero(ch);
int i = ;
int flag = -;
int ret = ;
while (n1) {
ch[i++] = n1 % + '';
n1 /= ;
}
for (int j = i - ; j > ; --j) {
if (ch[j] == '' && ch[j - ] == '') {
flag = j - ;
break;
}
}
n1 = n / ;
int w = ;
for (int j = ; j <= i; ++j) {
for (int jj = ; jj < ch[j] - ''; ++jj) {
int t = (n1 * ) * w % ;
if (jj == && ch[j + ] == '') {
t = (n1 / * ) * w % ;
ret += dp[j][][][( - t) % ] + dp[j ][][][( - t) % ];
continue;
}
if (flag > j) {
ret += dp[j][jj][][( - t) % ] + dp[j][jj][][( - t) % ];
} else {
ret += dp[j][jj][][( - t) % ];
}
}
w *= ;
n1 /= ;
}
if (n % == && flag != -) ret++;
return ret;
}
int main() {
//freopen("data.out", "w", stdout);
//freopen("data.in", "r", stdin);
//cin.sync_with_stdio(false);
init();
while (cin >> n) {
cout << cal(n) << endl;
}
return ;
}

【dp】B-number的更多相关文章

  1. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  2. HDOJ 1159 Common Subsequence【DP】

    HDOJ 1159 Common Subsequence[DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  3. 【LeetCode】792. Number of Matching Subsequences 解题报告(Python)

    [LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  4. 【LeetCode】673. Number of Longest Increasing Subsequence 解题报告(Python)

    [LeetCode]673. Number of Longest Increasing Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https:/ ...

  5. 【POJ2104】【HDU2665】K-th Number 主席树

    [POJ2104][HDU2665]K-th Number Description You are working for Macrohard company in data structures d ...

  6. 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)

    [SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...

  7. Kattis - honey【DP】

    Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...

  8. HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】

    HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...

  9. HDOJ 1257 最少拦截系统 【DP】

    HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  10. HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】

    HDOJ_1087_Super Jumping! Jumping! Jumping! [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

随机推荐

  1. The All-in-One Note

    基础 操作系统 I/O 模型 阻塞式 I/O 模型(blocking I/O) 描述:在阻塞式 I/O 模型中,应用程序在从调用 recvfrom 开始到它返回有数据报准备好这段时间是阻塞的,recv ...

  2. echarts画中国地图,省市区地图分享

    中国地图 四川地图 重庆地图 源码分享: https://github.com/livelyPeng/ec-map

  3. 4. SOFAJRaft源码分析— RheaKV初始化做了什么?

    前言 由于RheaKV要讲起来篇幅比较长,所以这里分成几个章节来讲,这一章讲一讲RheaKV初始化做了什么? 我们先来给个例子,我们从例子来讲: public static void main(fin ...

  4. JVM - 复习

    内存模型图 程序计数器(PC) 程序计数器的特点 PC是一小块内存空间,用于记录当前线程执行的字节码指令的地址.如果执行的是本地方法(native),PC里此时显示Undefined 优点: 控制程序 ...

  5. 组合+封装+property+多态+鸭子类型(day21)

    目录 昨日回顾 继承 什么是继承 继承的目的 什么是抽象 继承背景下,对象属性的查找顺序 派生 什么是派生 子类派生出新的属性,重用父类的属性 新式类和经典类 钻石继承的继承顺序 今日内容 一.组合 ...

  6. Nginx在Window上简单的使用

    先上Nginx在Window上的基本常用指令: IP_hase也可以解决Session共享的问题:不过不推荐这样使用,建议使用 Memcache/redis来处理 session共享的问题 轮询还是权 ...

  7. mysql的一些常用操作(一)

    1.启动Mysql服务 net start mysql 2.进入mysql环境中,由于自己没有设置密码,直接回车进入即可(要将bin加入到环境变量path中) mysql -u root -p 3.创 ...

  8. ThreadPoolExecutor源码中的适配器模式

    什么是适配器模式 网上已有很多的教程,不细讲了.可以参考:五分钟了解设计模式(3)---适配器模式 在适配器模式中,一定要识别清楚,Target Adaptee Adapter分别是哪些类或接口,这样 ...

  9. SpringBoot配置文件之Yml语法

    一 使用 YAML 而不是 Properties YAML是 JSON 的超集,因此,它是用于指定分层配置数据的便捷格式.只要 class 路径上有SnakeYAML library,SpringAp ...

  10. jwt token

    1 ,session 认证机制: ,用户登录,传递用户名和密码给客户端 ,服务器进行用户名和密码的校验,如果校验成功,将用户保存到session ,将sessionid通过cookie返回给客服端,客 ...