cswork / OA打开练习工作台

MoveworksOA #2

Number of Balanced Strings

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)动规入门

Write a Java program with a function named numberOfBalancedStrings that counts the number of ways we can make a balanced string of size n and difference d. A Balanced string is a string where the difference between adjacent characters does not exceed d.

Constraints

N/A

Example 1

Input:

n = 3
d = 3

Output:

224

Explanation: There are 224 ways to create a balanced string of size 3 with a maximum adjacent character difference of 3.

Example 2

Input:

n = 2
d = 2

Output:

124

Explanation: There are 124 ways to create a balanced string of size 2 with a maximum adjacent character difference of 2.