cswork / OA打开练习工作台

SnowflakeOA #9

Work Schedule — Fill Question Marks to Match Total

估计中等可在线判题

考点(AI 标注)回溯枚举

Replace each question mark in the seven-digit pattern with a value in 0..day_hours so that the weekly total is exactly work_hours. Fixed digits stay unchanged. Return all schedules in ascending lexicographic order. At least one valid schedule is guaranteed.

输入格式

The first line contains work_hours day_hours, and the second line contains the 7-digit pattern. 1≤work_hours≤56, 1≤day_hours≤8; the pattern consists of 0..8 or ?, and fixed hours do not exceed the daily limit. The original constraints omitted ?, which is restored from the body text.

输出格式

First output the number of schedules R, then one 7-digit schedule per line; all schedules must be output in ascending lexicographic order.

样例 1

输入:

3 2
?1?0000

输出:

3
0120000
1110000
2100000

样例 2

输入:

1 1
???????

输出:

7
0000001
0000010
0000100
0001000
0010000
0100000
1000000

样例 3

输入:

56 8
???????

输出:

1
8888888

样例说明

The answers to the three public examples are, in order: 3 0120000 1110000 2100000; 7 0000001 0000010 0000100 0001000 0010000 0100000 1000000; 1 8888888. All examples have been verified by independent small-scale enumeration or state search.