题目传送门

 /*
找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one ()
http://www.cnblogs.com/crazyapple/p/3315436.html
数位DP:http://blog.csdn.net/libin56842/article/details/11580497
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f; int is_one(long long n)
{
long long m = n;
long long i = n / * ; for (; i<=m; ++i)
{
long long tmp = i; int sum = ;
while (tmp)
{
sum += tmp % ;
tmp /= ;
}
if (sum % == ) return ;
} return ;
} long long get_num(long long n)
{
if (n < ) return ;
if (n <= ) return ; return n/ + is_one (n);
} int main(void) //HDOJ 4722 Good Numbers
{
//freopen ("G.in", "r", stdin); int t, cas = ;
long long l, r;
scanf ("%d", &t);
while (t--)
{
scanf ("%I64d%I64d", &l, &r); printf ("Case #%d: %I64d\n", ++cas, get_num (r) - get_num (l-));
} return ;
} /*
Case #1: 0
Case #2: 1
Case #3: 1
*/

 /*
数位DP:基础题,对于一个数,把它每位数分出来,从最高位开始枚举。dp[i][(j+k)%10] += dp[i+1][j];
dp[i][j]表示前i位数和取模是j的个数
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; typedef long long ll;
const int MAXN = ;
const int INF = 0x3f3f3f3f;
ll dp[MAXN][MAXN];
int dig[MAXN]; ll work(ll n) {
ll tmp = n; int len = ;
memset (dig, , sizeof (dig));
while (tmp) {
dig[++len] = tmp % ;
tmp /= ;
}
memset (dp, , sizeof (dp)); int x = ;
for (int i=len; i>=; --i) {
for (int j=; j<; ++j) {
for (int k=; k<; ++k) {
dp[i][(j+k)%] += dp[i+][j];
}
}
for (int j=; j<dig[i]; ++j) dp[i][(x+j)%]++;
x = (x + dig[i]) % ;
}
if (!x) dp[][]++;
return dp[][];
} int main(void) { //HDOJ 4722 Good Numbers
int T, cas = ; scanf ("%d", &T);
while (T--) {
ll l, r; scanf ("%I64d%I64d", &l, &r);
printf ("Case #%d: %I64d\n", ++cas, work (r) - work (l-));
} return ;
}

数位DP

找规律/数位DP HDOJ 4722 Good Numbers的更多相关文章

  1. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

  2. 2017年icpc西安网络赛 Maximum Flow (找规律+数位dp)

    题目 https://nanti.jisuanke.com/t/17118 题意 有n个点0,1,2...n-1,对于一个点对(i,j)满足i<j,那么连一条边,边权为i xor j,求0到n- ...

  3. CF809C(找规律+数位DP)

    老年选手需要多写一些思维题qwq. 通过打表很容易发现对于(i,j),值为(i-1)^(j-1)+1,然后本题就没了qwq. 矩阵差分还是很容易想到的,容斥成四个矩阵. 然后看到异或很容易想到三件事: ...

  4. [数位dp] spoj 10738 Ra-One Numbers

    题意:给定x.y.为[x,y]之间有多少个数的偶数位和减去奇数位和等于一. 个位是第一位. 样例: 10=1-0=1 所以10是这种数 思路:数位dp[i][sum][ok] i位和为sum 是否含有 ...

  5. hdu 4722 Good Numbers 规律 数位dp

    #include<iostream> #include<cstring> #include<cstdio> #include<vector> #incl ...

  6. Codeforces Round #260 (Div. 2) A , B , C 标记,找规律 , dp

    A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  7. 数位DP CF 55D Beautiful numbers

    题目链接 题意:定义"beautiful number"为一个数n能整除所有数位上非0的数字 分析:即n是数位所有数字的最小公倍数的倍数.LCM(1到9)=2520.n满足是252 ...

  8. 【数位DP】CF55D Beautiful numbers

    $dp[x][p][pp]$表示第x位,当前已有数字mod 2520(1~9数字的lcm)为p,当前各位数字的lcm为pp 观察到数组太大,考虑压缩,第三维lcm最多只有9个数字,打表发现最多只有48 ...

  9. 剑指 Offer 44. 数字序列中某一位的数字 + 找规律 + 数位

    剑指 Offer 44. 数字序列中某一位的数字 Offer_44 题目描述 题解分析 java代码 package com.walegarrett.offer; /** * @Author Wale ...

随机推荐

  1. 深入理解Java中的继承

    对于面向对象的程序设计而言,每一个程序员都应该去了解Java中的封装,继承和多态,那么我今天来说的主要是以继承为核心的主题. 一.关于对继承的理解. 继承是面向对象的三大特性之一,是java中实现代码 ...

  2. 使用python在SAE上搭建一个微信应用,使用有道翻译的api进行在线翻译

    1. 准备,先在使用python一步一步搭建微信公众平台(一)中基本实现自动回复的功能后,接着在有道词典上申请一个key,http://fanyi.youdao.com/openapi?path=da ...

  3. Summarize Series For Burying My College

    Summarize  Series  For  Burying  My  College                                             For  Grade ...

  4. MyBatis 3源码分析

    Mybatis3.2源码分析: 一.加载配置文件.     使用SAX解析配置文件.读取xml配置文件后,调用XMLConfigBuilder.parse()方法,在parse方法中再调用parseC ...

  5. 在link的url里新增参数

    (文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) <%= link_to image_tag("/images/icons/aaa. ...

  6. Dynamic Morphing Square(动态变形矩阵)

    题目描述: 解题思路: 先对输入的N进行判断,是否不小于3,如果小于3,需要继续输入一个新的数,知道输入的N比3大. 第一个打印的矩阵,*号为最外面一圈,其余全为-. 第二个打印的矩阵,*号向内缩减了 ...

  7. The CompilerVersion constant identifies the internal version number of the Delphi compiler.

    http://delphi.wikia.com/wiki/CompilerVersion_Constant The CompilerVersion constant identifies the in ...

  8. 速度之王 — LZ4压缩算法(三)

    LZ4使用 make / make clean 得到可执行程序:lz4.lz4c Usage: ./lz4 [arg] [input] [output] input : a filename Argu ...

  9. PHP 的__call()

    PHP5 的对象新增了一个专用方法 __call(),这个方法用来监视一个对象中的其它方法.如果你试着调用一个对象中不存在或被权限控制中的方法,__call 方法将会被自动调用. 例七:__call ...

  10. ASP.NET小知识

    所有System.Web.UI.*命名空间下的内容可以称为Web From,而System.Web.*命名空间下的其他内容可以称为ASP.NET. @section用法:配合母版页中的@RenderS ...