QOJ.ac

QOJ

时间限制: 10 s 内存限制: 256 MB 总分: 100

#23803. 一年級生

统计

題目描述

JOI 君是小學 $1$ 年級學生。JOI 君非常喜歡剛學到的加法和減法,每當看到一排數字時,他就會在最後 $2$ 個數字之間填入 =,並在其餘相鄰數字之間必定填入 + 或 -,以此構造等式來玩耍。例如,由 8 3 2 4 8 7 2 4 0 8 8 可以構造出等式 8+3-2-4+8-7-2-4-0+8=8。

構造出等式後,JOI 君會透過計算來驗證它是否為一個正確的等式。然而,JOI 君還不知道負數,也不會計算超過 $20$ 的數。因此,在正確的等式中,只有從左往右計算等號左邊時,計算過程中所出現的所有數都在 $0$ 以上 $20$ 以下的等式,才是 JOI 君能夠驗證的正確等式。例如,8+3-2-4-8-7+2+4+0+8=8 雖然是正確的等式,但由於計算途中出現的 8+3-2-4-8 是負數,JOI 君無法驗證這個等式是否正確。

給定一列數字作為輸入,請撰寫程式求出 JOI 君能夠構造並驗證的正確等式的個數。

輸入格式

輸入檔案共 $2$ 行。第 $1$ 行包含一個整數 $N$($3 \le N \le 100$),表示排列的數字個數。第 $2$ 行包含 $N$ 個 $0$ 以上 $9$ 以下的整數,以空格分隔。

在給定的 $60\%$ 的輸入資料中,JOI 君能夠構造並驗證的正確等式的個數不超過 $2^{31}-1$。此外,在所有給定的輸入資料中,JOI 君能夠構造並驗證的正確等式的個數不超過 $2^{63}-1$。

輸出格式

輸出 $1$ 行一個整數,表示 JOI 君能夠構造並驗證的正確等式的個數。

範例

範例輸入 1

11
8 3 2 4 8 7 2 4 0 8 8

範例輸出 1

10

範例輸入 2

40
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1

範例輸出 2

7069052760

在範例輸入 $1$ 中,JOI 君能夠構造並驗證以下 $10$ 個正確的等式:

  • 8+3-2-4+8-7-2-4-0+8=8
  • 8+3-2-4+8-7-2-4+0+8=8
  • 8+3+2+4-8-7+2-4-0+8=8
  • 8+3+2+4-8-7+2-4+0+8=8
  • 8+3+2-4+8-7+2+4-0-8=8
  • 8+3+2-4+8-7+2+4+0-8=8
  • 8-3+2+4-8+7+2+4-0-8=8
  • 8-3+2+4-8+7+2+4+0-8=8
  • 8-3+2-4+8+7+2-4-0-8=8
  • 8-3+2-4+8+7+2-4+0-8=8

因此輸出 $10$。

在範例輸入 $2$ 中,請注意答案超出了 $32$ 位元有號整數的範圍。

($2015$ 年 $2$ 月 $21$ 日追記) 經使用者指出,發現範例輸入 $1$ 說明中的等式存在錯誤,現已修正。第 $5$ 個等式原為 8+3-2-4+8-7+2+4-0-8=8,現已修正為 8+3+2-4+8-7+2+4-0-8=8。此外,第 $6$ 個等式原為 8+3-2-4+8-7+2+4+0-8=8,現已修正為 8+3+2-4+8-7+2+4+0-8=8。

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.