51 Nod 1042 数位dp
1042 数字0-9的数量
- 1 秒
- 131,072 KB
- 10 分
- 2 级题
输入
两个数a,b(1 <= a <= b <= 10^18)
输出
输出共10行,分别是0-9出现的次数
输入样例
10 19
输出样例
1
11
1
1
1
1
1
1
1
1
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<time.h>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 20005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
#define mclr(x,a) memset((x),a,sizeof(x))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-5
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii; inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int len;
ll a, b;
int num[20];
ll dp[20][20002]; ll dfs(int pos, int limit, int lead, ll sum,int dig) {
if (pos == 0)return sum;
if (!limit&&lead&&dp[pos][sum] != -1)return dp[pos][sum];
ll ans = 0;
int up = limit ? num[pos] : 9;
for (int i = 0; i <= up; i++) {
ans += dfs(pos - 1, limit && (i == up), lead || i, sum + ((i == dig)&&(lead||i)), dig);
}
if (lead && !limit)dp[pos][sum] = ans;
return ans; } ll sol(ll a, ll dig) {
mclr(dp, -1); len = 0;
while (a) {
num[++len] = a % 10; a /= 10;
}
ll ans = 0;
ans = dfs(len, 1, 0, 0, dig);
return ans;
}
int main()
{
// ios::sync_with_stdio(0);
rdllt(a); rdllt(b);
for (int i = 0; i <= 9; i++) {
printf("%lld\n", sol(b, i) - sol(a - 1, i));
}
return 0;
}
51 Nod 1042 数位dp的更多相关文章
- 51nod 1042 数位dp
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1042 1042 数字0-9的数量 基准时间限制:1 秒 空间限制:131 ...
- 51 nod 1055 最长等差数列(dp)
1055 最长等差数列 基准时间限制:2 秒 空间限制:262144 KB 分值: 80 难度:5级算法题 N个不同的正整数,找出由这些数组成的最长的等差数列. 例如:1 3 5 6 8 9 ...
- 51 nod 1610 路径计数(Moblus+dp)
1610 路径计数 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 路径上所有边权的最大公约数定义为一条路径的值. 给定一个有向无环图.T次修改操作,每次修改一 ...
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- Codeforces Beta Round #51 D. Beautiful numbers(数位dp)
题目链接:https://codeforces.com/contest/55/problem/D 题目大意:给你一段区间[l,r],要求这段区间中可以整除自己每一位(除0意外)上的数字的整数个数,例如 ...
- 数位类统计问题--数位DP
有一类与数位有关的区间统计问题.这类问题往往具有比较浓厚的数学味道,无法暴力求解,需要在数位上进行递推等操作.这类问题往往需要一些预处理,这就用到了数位DP. 本文地址:http://www.cnbl ...
- Tsinsen A1516. fx 数位dp
题目: http://www.tsinsen.com/A1516 A1516. fx 时间限制:2.0s 内存限制:256.0MB 总提交次数:164 AC次数:72 平均分:51. ...
- 【HDU 3652】 B-number (数位DP)
B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose de ...
- 【HDU3530】 [Sdoi2014]数数 (AC自动机+数位DP)
3530: [Sdoi2014]数数 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 682 Solved: 364 Description 我们称一 ...
随机推荐
- 一张图记住TCP/IP通讯中的IP地址配置
TCP/IP通讯情景: 用网线将计算机A(服务器Server)和计算机B(Client)连接起来.程序代码在计算机A中,计算机B中安装有TCP/IP通讯助手. (图中屏幕大的是计算机A,屏幕小的笔记本 ...
- Openssl gendsa命令
一.简介 gendsa命令能够根据DSA密钥参数生成DSA密钥 二.语法 openssl gendsa [-out filename] [-passout out] [-rand file(s)] [ ...
- Python手机开发调用DLL实现部分ADB功能-乾颐堂
近期学了一点Python,然后正好有一个手机同步工具方面的预研工作要完成. 要实现PC与手机的通信,首先要找到他们的通信协议,还好的是Android有完善的协议:ADB ADB的代码是开源的,而且支持 ...
- HTTP 499状态码 nginx下499错误详解-乾颐堂
日志记录中HTTP状态码出现499错误有多种情况,我遇到的一种情况是nginx反代到一个永远打不开的后端,就这样了,日志状态记录是499.发送字节数是0. 老是有用户反映网站系统时好时坏,因为线上的产 ...
- [SoapUI] SOAP UI-Groovy Useful Commands
Hi All, I have posted the SOAPUI and Groovy useful commands that may help you in your testing. Below ...
- Microsoft(C)注册服务器(32位)CPU占用高
Microsoft(C)注册服务器(32位)CPU占用高 摘自:https://blog.csdn.net/jtsqrj/article/details/83034252 2018年10月12日 23 ...
- charles4.2下载与破解方法以及配置https.RP
Charles下载地址 地址:https://www.charlesproxy.com/latest-release/download.do 2. Charles破解 破解地址:https://www ...
- PBOC电子现金的交易流程
做一个电子现金的交易: 第一步当然是选中当前的应用, 方法是调用select命令, 传入当前的应用AID号, 如果卡片的状态码返回9000,则表示选中成功. 下面举一个例子: 发送: 00 a4 04 ...
- 大前端涉猎之前后端交互总结3:使用PHP进行表单数据删除与查询
1 首先:获取用户 id,根据id 删除指定的数据. 在链接完数据库之后,通过$_GET 超全局变量,获取删除的书内容 $id = $_GET['id']; 2 准备delete SQL语句: $sq ...
- C# 释放资源的规范写法
static class CSharp_3 { /* ---------------------------------------- * 以下学习资源的释放:IDispose和析构函数 * 1.ID ...