File tree 1 file changed +11
-11
lines changed
solution/2300-2399/2338.Count the Number of Ideal Arrays
1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change 1
1
class Solution :
2
2
def idealArrays (self , n : int , maxValue : int ) -> int :
3
- @cache
4
- def dfs (i , cnt ):
5
- res = c [- 1 ][cnt - 1 ]
6
- if cnt < n :
7
- k = 2
8
- while k * i <= maxValue :
9
- res = (res + dfs (k * i , cnt + 1 )) % mod
10
- k += 1
11
- return res
12
-
13
3
c = [[0 ] * 16 for _ in range (n )]
14
4
mod = 10 ** 9 + 7
15
5
for i in range (n ):
16
6
for j in range (min (16 , i + 1 )):
17
7
c [i ][j ] = 1 if j == 0 else (c [i - 1 ][j ] + c [i - 1 ][j - 1 ]) % mod
8
+ f = [[0 ] * 16 for _ in range (maxValue + 1 )]
9
+ for i in range (1 , maxValue + 1 ):
10
+ f [i ][1 ] = 1
11
+ for j in range (1 , 15 ):
12
+ for i in range (1 , maxValue + 1 ):
13
+ k = 2
14
+ while k * i <= maxValue :
15
+ f [k * i ][j + 1 ] = (f [k * i ][j + 1 ] + f [i ][j ]) % mod
16
+ k += 1
18
17
ans = 0
19
18
for i in range (1 , maxValue + 1 ):
20
- ans = (ans + dfs (i , 1 )) % mod
19
+ for j in range (1 , 16 ):
20
+ ans = (ans + f [i ][j ] * c [- 1 ][j - 1 ]) % mod
21
21
return ans
You can’t perform that action at this time.
0 commit comments