P2602 ZJOI2010 數字計數

2021-10-07 02:34:09 字數 903 閱讀 5019

p2602

題目描述

給定兩個正整數 a 和 b,求在 [a,b]中的所有整數中,每個數碼(digit)各出現了多少次。

輸入格式

僅包含一行兩個整數 a,b,含義如上所述。

輸出格式

包含一行十個整數,分別表示 0∼9 在 [a,b]**現了多少次。

1 99

9 20 20 20 20 20 20 20 20 20

對於 30% 的資料,保證 a≤b≤10^6

;對於 100% 的資料,保證 1≤a≤b≤10^12

。lead為false表示有前導0,limit為true表示該位置有限制。

#include

#include

#include

#include

using

namespace std;

typedef

long

long ll;

ll dp[55]

[55], a[

100]

;ll l, r;

ll dfs

(int pos,

bool lead,

bool limit,

int dig, ll sum)if(

!limit && lead)

dp[pos]

[sum]

= ans;

return ans;

}ll solve

(ll n,

int dig)

return

dfs(pos,

false

,true

, dig,0)

;}intmain()

return0;

}

P2602 ZJOI2010 數字計數

題目描述 給定兩個正整數a和b,求在 a,b 中的所有整數中,每個數碼 digit 各出現了多少次。輸入格式 輸入檔案中僅包含一行兩個整數a b,含義如上所述。輸出格式 輸出檔案中包含一行10個整數,分別表示0 9在 a,b 現了多少次。輸入輸出樣例 輸入 1 1 99 輸出 1 9 20 20 2...

洛谷P2602 ZJOI2010 數字計數 題解

很裸的一道數字dp的板子 定義f 當前列舉到的數字 當前數字之前的答案 列舉的數字 其它的套板子就可以了,要注意一下字首0的判斷 1 include2 include3 include4 include5 include6 include7 using namespace std 8 typedef...

ZJOI2010 數字計數

題目描述 給定兩個正整數a和b,求在 a,b 中的所有整數中,每個數碼 digit 各出現了多少次。輸入格式 輸入檔案中僅包含一行兩個整數a b,含義如上所述。輸出格式 輸出檔案中包含一行10個整數,分別表示0 9在 a,b 現了多少次。輸入輸出樣例 輸入 1 1 99 輸出 1 9 20 20 2...