[题目链接]

http://poj.org/problem?id=2282

[算法]

数位DP

[代码]

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; int i;
long long a,b;
long long f[][][]; inline void dp(long long m)
{
long long i,j,k,x;
memset(f,,sizeof(f));
f[][][] = ;
for (i = ; i <= ; i++)
{
for (j = ; j <= ; j++)
{
for (k = ; k <= i; k++)
{
if (j != m)
{
for (x = ; x <= ; x++)
f[i][j][k] += f[i - ][x][k];
} else if (k >= )
{
for (x = ; x <= ; x++)
f[i][j][k] += f[i - ][x][k - ];
}
}
}
}
}
inline long long calc(long long x,long long t)
{
long long i,j,k,len = ;
long long res = ;
long long cnt = ;
long long a[];
memset(a,,sizeof(a));
while (x != )
{
a[++len] = x % ;
x /= ;
}
reverse(a + ,a + len + );
for (i = ; i <= len; i++)
{
for (j = ; j <= ; j++)
{
for (k = ; k <= len - i + ; k++)
res += f[len - i + ][j][k] * k;
}
}
for (i = ; i <= len; i++)
{
for (j = ; j < a[i]; j++)
{
if (i == && !j) continue;
for (k = cnt; k <= len; k++)
{
res += f[len - i + ][j][k - cnt] * k;
}
}
if (a[i] == t) cnt++;
}
return res;
} int main()
{ while (scanf("%lld%lld",&a,&b) && (a || b))
{
if (a > b) swap(a,b);
for (i = ; i < ; i++)
{
dp(i);
printf("%lld ",calc(b + ,i) - calc(a,i));
}
dp();
printf("%lld\n",calc(b + ,) - calc(a,));
} return ; }

[POJ 2282] The Counting Problem的更多相关文章

  1. POJ - Problem 2282 - The Counting Problem

    整体思路:对于每一位,先将当前未达到$limit$部分的段 [如 $0$ ~ $10000$] 直接处理好,到下一位时再处理达到$limit$的部分. · $1 × 10 ^ n$以内每个数(包括$0 ...

  2. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  3. UVA 1640 The Counting Problem UVA1640 求[a,b]或者[b,a]区间内0~9在里面各个数的数位上出现的总次数。

    /** 题目:UVA 1640 The Counting Problem UVA1640 链接:https://vjudge.net/problem/UVA-1640 题意:求[a,b]或者[b,a] ...

  4. POJ 3468.A Simple Problem with Integers-线段树(成段增减、区间查询求和)

    POJ 3468.A Simple Problem with Integers 这个题就是成段的增减以及区间查询求和操作. 代码: #include<iostream> #include& ...

  5. poj 3468 A Simple Problem with Integers 【线段树-成段更新】

    题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...

  6. 线段树(成段更新) POJ 3468 A Simple Problem with Integers

    题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...

  7. POJ 1152 An Easy Problem! (取模运算性质)

    题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...

  8. 『The Counting Problem 数位dp』

    The Counting Problem Description 求 [L,R]内每个数码出现的次数. Input Format 若干行,一行两个正整数 L 和 R. 最后一行 L=R=0,表示输入结 ...

  9. POJ2282 The Counting Problem

    题意 Language:DefaultEspañol The Counting Problem Time Limit: 3000MS Memory Limit: 65536K Total Submis ...

随机推荐

  1. HTML简单入门

    - Java攻城狮学习路线 - 基本结构 标准文档:www.w3.org <!DOCTYPE html> <html> <head> <meta charse ...

  2. react中withRouter解决props返回为空

    利用 react + antd 框架书写导航栏时,遇到了几个坑,分别是一级菜单和二级菜单在点击的情况下,高亮没有任何问题,但是再点击浏览器返回按钮时,却就乱套了. 1. 二级菜单中,我们可以通过 pr ...

  3. Android 解析XML—pull解析方式

    在Android中,常见的XML解析器分别为SAX解析器.DOM解析器和PULL解析器,其中PULL解析器小巧轻便,解析速度快,简单易用,非常适合在Android移动设备中使用,Android系统内部 ...

  4. Spring AOP之动态代理

    软件151 李飞瑶 一.Spring 动态代理中的基本概念  1.关注点(concern)    一个关注点可以是一个特定的问题,概念.或者应用程序的兴趣点.总而言之,应用程序必须达到一个目标    ...

  5. Centos6.6 安装Subversion服务

    一.介绍 Subversion 简称就是svn服务器,用来托管代码的,类似的还有git 1)Centos6.6 2)Subversion 二.安装 yum -y install subversion ...

  6. js 判断是否为数字

    if (data.value === "" || data.value == null) { return false; } console.log(!isNaN(data.val ...

  7. socket主要函数介绍

    1.   基本套接字函数(1)socket函数原型 socket(建立一个socket文件描述符) 所需头文件 #include <sys/types.h> #include <sy ...

  8. 【剑指Offer】61、序列化二叉树

      题目描述:   请实现两个函数,分别用来序列化和反序列化二叉树.   解题思路:   序列化是指将结构化的对象转化为字节流以便在网络上传输或写到磁盘进行永久存储的过程.反序列化是指将字节流转回结构 ...

  9. LA 4327

    Panagola, The Lord of city F likes to parade very much. He always inspects his city in his car and e ...

  10. 一键安装LNMP(适合centos7)

    1.准备工作,下载源码包 wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar ...