[POJ 2282] The Counting Problem
[题目链接]
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的更多相关文章
- POJ - Problem 2282 - The Counting Problem
整体思路:对于每一位,先将当前未达到$limit$部分的段 [如 $0$ ~ $10000$] 直接处理好,到下一位时再处理达到$limit$的部分. · $1 × 10 ^ n$以内每个数(包括$0 ...
- POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...
- 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] ...
- POJ 3468.A Simple Problem with Integers-线段树(成段增减、区间查询求和)
POJ 3468.A Simple Problem with Integers 这个题就是成段的增减以及区间查询求和操作. 代码: #include<iostream> #include& ...
- poj 3468 A Simple Problem with Integers 【线段树-成段更新】
题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...
- 线段树(成段更新) POJ 3468 A Simple Problem with Integers
题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...
- POJ 1152 An Easy Problem! (取模运算性质)
题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...
- 『The Counting Problem 数位dp』
The Counting Problem Description 求 [L,R]内每个数码出现的次数. Input Format 若干行,一行两个正整数 L 和 R. 最后一行 L=R=0,表示输入结 ...
- POJ2282 The Counting Problem
题意 Language:DefaultEspañol The Counting Problem Time Limit: 3000MS Memory Limit: 65536K Total Submis ...
随机推荐
- CSS多列布局(实例)
前言 一列布局 二列布局 三列布局 1 一列布局 一列布局: HTML部分 <!DOCTYPE html> <html> <head> <meta chars ...
- HTML学习笔记——DOCTYPE和DTD,标准模式和兼容模式
主要涉及知识点: HTML与XHTML HTML与XHTML的区别 DOCTYPE与DTD的概念 DTD的分类以及DOCTYPE的声明方式 标准模式(Standard Mode)和兼容模式(Quirc ...
- Gradle sync failed: Could not find method android() for arguments 错误的解决办法
这个问题本质上是Android-gradle的一个使用限制. 对应的英文文档android_tool文档 如果你的App包含了多个Android模块, 应该尽量避免给每个模块手动指定编译SDK版本. ...
- 【MySQL】源码安装
操作系统:Red Hat Enterprise Linux Server release 6.5 Mysql安装包:mysql-5.6.4-m7.tar.zip,下载地址:http://pan.bai ...
- 极客学院免费VIP
[手快福利]用我的链接注册极客学院,你我都能免费得30天VIP!6500+编程开发视频教程随便学,还能下载资料和源码 http://e.jikexueyuan.com/invite/index.htm ...
- UNIX SOCKET编程简介
1 . Layered Model of Networking Socket 编程的层次模型如下图所示, 最上面是应用层,应用层下面的是 SOCKET API 层,再下面是传输层和网络层 ...
- 【转载】深入理解Java的接口和抽象类
深入理解Java的接口和抽象类 对于面向对象编程来说,抽象是它的一大特征之一.在Java中,可以通过两种形式来体现OOP的抽象:接口和抽象类.这两者有太多相似的地方,又有太多不同的地方.很多人在初学的 ...
- 【转载】JSP详解(四大作用域九大内置对象等)
前面讲解了Servlet,了解了Servlet的继承结构,生命周期等,并且在其中的ServletConfig和ServletContext对象有了一些比较详细的了解,但是我们会发现在Servlet中编 ...
- spotlight on mysql 监控
. 安装 下载地址:https://pan.baidu.com/s/1qYi3lec 官网地址——https://www.quest.com/common/registration.aspx?requ ...
- 16._source元数据