[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 ...
随机推荐
- mvc3结合spring.net-依赖注入
namespace Tuzi.Models.IService { public interface IPersonService { string say(string words); } names ...
- Windows下错误码全解析
windows系统下,调用函数出错时.可以调用GetLastError函数返回错误码.但是GetLastError函数返回值是DWORD类型,是一个整数.如果想要知道函数调用的真正错误原因,就需要对这 ...
- Java数据的基本类型
整数类型: byte:8位(1个字节) eg:byte x=2,y: 错误实例:byte b:b=b+3: 其中b=b+3是错误的,应该是b=(byte)(b+3)强制转换: short:16位( ...
- hibernate_07_单表操作_增删改操作
首先,创建类对象 package com.imooc.hibernate; public class Address { private String postcode; //邮编 private S ...
- 释放Win8.1 WinSxS冗余更新,微软Dism来解决
命令提示符(管理员) dism /online /Cleanup-Image /StartComponentCleanup /ResetBase 有些文章不建议使用 /RestBase,可能会有风险.
- C#让电脑发声,播放声音
//1. [DllImport("Kernel32.dll")] //引入命名空间 using System.Runtime.InteropServices; public sta ...
- C# 根据空格数截取
#region --根据空格数截取 ; ; //循环截取 , }; while (!sr.EndOfStream) { ; i < strTest.Length - ; i++) { ).Tri ...
- java操作Excel的poi 格式设置
格式设置 package com.java.poi; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi. ...
- MySQL在Linux下的表名如何不区分大小写
MySQL在Linux下的表名如何不区分大小写 今天测试的时候,遇到一些问题,明明看到数据,就是查不出来;后来发现,在linux下, mysql的表名区分大小写,而在windows下是不区分,从w ...
- eas之获取当前登陆信息
public void getSystemInfo() { // SysContext工具类可获取当前登陆用户的信息,可根据需要进行调用. // 举两例如下: ...