[题目链接]

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. CSS的常用属性(三)

    静态定位 position: static (默认) 标准流 绝对定位 position: absolute 特点: 元素使用绝对定位之后,不占据原来的位置(脱标) 元素使用绝对定位,位置是从浏览器出 ...

  2. eclipse中server 没有tomcat选项

    eclipse集成Tomcat: 打开eclipse - 窗口 - 首选项 - 服务器 - 运行时环境 找到Tomcat然后添加. eclipse添加插件: 开发WEB项目时要集成Tomcat可以并不 ...

  3. Android RecyclerView初体验

    很早之前就听说过RecyclerView这个组件了,但一直很忙没时间学习.趁着周末,就花了一天时间来学习RecyclerView. 准备工作 在Android Studio里新建一个Android项目 ...

  4. 基于神经网络的混合计算(DNC)-Hybrid computing using a NN with dynamic external memory

    前言: DNC可以称为NTM的进一步发展,希望先看看这篇译文,关于NTM的译文:人工机器-NTM-Neutral Turing Machine 基于神经网络的混合计算 Hybrid computing ...

  5. MFC 添加文件路径 遍历文件

    .添加MFC选择文件路径,使用MessageBox显示信息. void CMyCalLawsDlg::OnBnClickedAddfolder() { wchar_t* p; wchar_t szPa ...

  6. Metadata

    元数据是关于数据的组织.数据域及其关系的信息,简言之,元数据就是关于数据的数据. Metadata is "data [information] that provides informat ...

  7. eslint推荐编码规范和airbnb推荐编码规范

    Eslint规范 for 循环禁止使用无限循环(这个非默认推荐) // bad for (var i = 0; i < 10; i--) { } for (var i = 10; i >= ...

  8. icheck使用

    1.使用: <link rel="stylesheet" href="css/skins/all.css">或者<link rel=" ...

  9. springboot:基础学习一 linux下后台启动springboot项目

    我们知道启动springboot的项目有三种方式: 运行主方法启动 使用命令 mvn spring-boot:run”在命令行启动该应用 运行“mvn package”进行打包时,会打包成一个可以直接 ...

  10. appium的等待

    在自动化过程中,元素出现受网络环境,设备性能等多种因素影响.因此元素加载的时间可能不一致,从而会导致元素无法定位超时报错,但是实际上元素是正常加载了的,只是出现时间晚一点而已.那么如何解决这个问题呢? ...