#P1043. [NOIP 2003 普及组] 数字游戏

    ID: 43 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp搜索2003NOIp 普及组前缀和

[NOIP 2003 普及组] 数字游戏

Description

Dingding has recently become obsessed with a number game. The game looks simple, but after many days of study he realized that winning under the simple rules is not easy. The game is as follows: in front of you is a circle of integers (a total of nn), and you must split them, in order, into mm consecutive parts. Within each part, sum the numbers; take each of the mm sums modulo 1010, then multiply these mm results to obtain a number kk. The goal is to make kk as large as possible or as small as possible.

For example, for the following circle of numbers (n=4n=4, m=2m=2):

For the minimum, ((21)mod10)×((4+3)mod10)=1×7=7((2-1)\bmod10)\times ((4+3)\bmod10)=1\times 7=7. For the maximum, ((2+4+3)mod10)×(1mod10)=9×9=81((2+4+3)\bmod10)\times (-1\bmod10)=9\times 9=81. Note in particular that, whether a number is negative or positive, the result of taking modulo 1010 is always non-negative.

Please write a program to help Dingding win this game.

Input Format

The first line contains two integers, nn (1n501\le n\le 50) and mm (1m91\le m\le 9). Each of the next nn lines contains one integer with absolute value 104\le 10^4, given in order around the circle, with the ends connected.

Output Format

Output 22 lines, each containing 11 non-negative integer. The first line is the minimum value your program obtains, and the second line is the maximum value.

4 2
4
3
-1
2

7
81

Hint

Problem Source: NOIP 2003 Junior, Problem 2.

Translated by ChatGPT 5