# 微软笔试题：寻找等和的最长不相交二元组（只想到O(n^2）dp的做法）

You are given an array A of integers. Find the maximum number of non-intersecting segments of length 2 (two adjacent elements), such that segments have an equal sum. For example, given A = [10,1, 3,1, 2, 2,1, 0, 4] there are three non-intersecting segments, each whose sum is equal to 4: (1, 3), (2, 2), (0,4). Another three non-intersecting segments are (3, 1), (2, 2), (0,4).

Write a function:

that, given an array A of N integers, returns the maximum number of segments with equal sums.

Examples:

1. Given A = [10,1, 3,1, 2, 2,1, 0, 4], the function should return 3, as explained above.

2. Given A = [5, 3, 1, 3, 2, 3], the function should return 1. Each sum of two adjacent elements is different from the others.

3. Given A = [9, 9, 9, 9, 9], the function should return 2.

4. Given A = [1, 5, 2, 4, 3, 3], the function should return 3. There are three segments: (1, 5), (2,4), (3,3) whose sums are equal to 6.

Write an ****efficient**** algorithm for the following assumptions:

- N is an integer within the range [2 - 100,000]

- each element of array A is an integer within the range [0 - 1,000,000,000]                                                                  05-11 3019
12-16 8112
04-27 4840
03-14 1848
02-28 270
04-04 715
10-21 167
04-10 116
04-08 855
02-01 3万+
08-04 315
03-15 77
05-07 591
04-08 601
04-11 1262
04-06 3269
04-12 810
04-06 1024
07-01 532
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客