[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 ...
随机推荐
- 如何通过putty软件远程登录并且控制linux平台
准备备工作: 下载putty远程登录软件,图标如下 打开linux主机. Linux主机准备条件: 1 配置IP ,如果大家使用虚拟机的话建议通过vm1或者vm8进行与本地真实机进行连接,同时注意要避 ...
- android黑科技系列——应用市场省流量更新(增量升级)原理解析
一.前言 最近在看热修复相关的框架,之前我们已经看过了阿里的Dexposed和AndFix这两个框架了,不了解的同学可以点击这里进行查看:Dexposed框架原理解析 和 AndFix热修复框架原理解 ...
- 【oracle开发】wmsys.wm_concat介绍
wmsys.wm_concat是一个聚合函数,其作用是将一列数据转换成一行,也就是我们常用的行专列,但是该函数是一个undocument函数,所以不推荐大家使用这个函数.因为在后续的版本中还提不提供这 ...
- sql 导入excel 遇到问题
ALTER TABLE tab1 add id int identity primary key (注意:必须加identity,否则添加会失败) //导入excel时候 先把主键去掉 变为可为空,之 ...
- 如何将一个已有的项目托管到github或是码云上?git的配置
场景一:已有的一个项目,要把它托管到Git上去,步骤和方法如下: 方法一: ①在工程的路径下 : git init 建一个裸仓库. ②远程仓库地址 :将本地的仓库和远程仓库关联 git remote ...
- python 生成HTmL报告页面
计划做一个html页面 py3.4 代码: # -*- coding=utf-8 -*- # import time,os class Template_mixin(object): "&q ...
- Keras手写识别例子(1)----softmax
转自:https://morvanzhou.github.io/tutorials/machine-learning/keras/2-2-classifier/#测试模型 下载数据: # downlo ...
- 【剑指Offer】16、合并两个排序的链表
题目描述: 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 解题思路: 首先需要判断几个特殊情况,即判断输入的两个指针是否为空.如果第一个 ...
- Google JavaScript Style Guide
转自:http://google.github.io/styleguide/javascriptguide.xml Google JavaScript Style Guide Revision 2.9 ...
- 操作符重载、继承(day08)
二十 操作符重载 函数操作符"()" 功能:让对象当做函数来使用 注:对参数的个数.返回类型没有限制 eg: class A{...}; A a; //a.operator()(1 ...