QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22795. 郵票

Statistics

給定郵票面值集合(如 {1, 3, 5})和信封最多張數(如五張)。求能支付的最長連續郵資區間。用 {1, 3, 5}、最多五張,可組成:

  1: 1        6: 1+5       11: 5+5+1     16: 5+5+3+3      21: 5+5+5+3+3
  2: 1+1      7: 5+1+1     12: 5+5+1+1   17: 5+5+5+1+1    22: ????
  3: 3        8: 5+3       13: 5+5+3     18: 5+5+5+3
  4: 1+3      9: 5+3+1     14: 5+5+3+1   19: 5+5+5+3+1
  5: 5       10: 5+5       15: 5+5+5     20: 5+5+5+5

似乎無法用至多五張組成 22 分。因此可組成 $[1,21]$,共 21 個連續面值。但最長連續區間不一定從 1 開始。

輸入格式

  • 第 $1$ 行:空格分隔整數 $S$($1 \le S \le 20$),種類數,及 $E$($1 \le E \le 10$),信封最多張數。

  • 第 $2$ 行:$S$ 個不同的空格分隔正整數,郵票面值($1 \le \text{stampval} \le 1000$)。

輸出格式

組合郵票能組成的連續面值個數的最大值。

範例

輸入格式 1

3 5
1 3 5

輸出格式 1

21

題目來源:1995 ACM 總決賽。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.