← 返回 walmartlabs 的题目列表Find All Valid Weekly Work Schedules
类型:online_judge
Problem: Find All Valid Weekly Work Schedules
Given three parameters:
workHours: total required working hours in a week, 0 <= workHours <= 56;
dayHours: maximum working hours per day, 0 <= dayHours <= 8;
pattern: a string of length 7, representing the schedule from Monday to Sunday.
Each character in pattern means:
'0' to '8': fixed working hours for that day;
'?': flexible, can be replaced by any integer from 0 to dayHours.
Return all valid schedules. Each schedule is a string of length 7 satisfying:
Every ? is replaced by a digit;
Daily hours do not exceed dayHours;
The total hours over 7 days equals exactly workHours.
Output the schedules in lexicographical order.
Input Format
workHours dayHours
pattern
Output Format
Print one valid schedule per line. If no valid schedule exists, print nothing.
Constraints
0 <= workHours <= 56
0 <= dayHours <= 8
pattern.length == 7
pattern[i] is '0' to '8' or '?'.
Example
Input:
24 4
08??840
Output:
0804840
0813840
0822840
0831840
0840840
Example
Input
24 4
08??840
Output
0804840
0813840
0822840
0831840
0840840