P2602 ZJOI2010 數字計數

2021-10-01 11:24:31 字數 1100 閱讀 4256

題目描述

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

輸入格式

輸入檔案中僅包含一行兩個整數a、b,含義如上所述。

輸出格式

輸出檔案中包含一行10個整數,分別表示0-9在[a,b]**現了多少次。

輸入輸出樣例

輸入 #1

1 99

輸出 #1

9 20 20 20 20 20 20 20 20 20

說明/提示

30%的資料中,a<=b<=10^6;

100%的資料中,a<=b<=10^12。

題解:這道題還是可以用dfs來解決的。

首先,既然dfs,就必須有多維狀態。同時這道題不涉及限制,僅僅是統計,那就可以不必記錄當前位,只需統計答案,同時記憶化即可。

#include

#include

#include

#include

#include

using

namespace std;

long

long f[15]

[15];

long

long a[15]

,len,l,r;

long

long

dfs(

long

long pos,

long

long sum,

long

long st,

long

long limit,

long

long dig)if(

!limit&&

!st)f[pos]

[sum]

=ret;

return ret;

}long

long

work

(long

long x,

long

long dig)

return

dfs(1,

0,1,

1,dig);}

intmain()

//cout//cout}

P2602 ZJOI2010 數字計數

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

洛谷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...