动态规划
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <ctype.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
int main()
{
int val;
int nums[201];
int dp[201][402];
int len = 0;
int i, j, k;
char s;
int res = 0;
while (~scanf("%d%c", &val, &s))
{
nums[len++] = val;
if (s != ' ')
break;
};
memset(dp, 0, sizeof(dp));
for (k = -200; k <= 200; k++)
for (i = 0; i < len; i++)
for (j = i + 1; j < len; j++)
if (nums[i] + k == nums[j])
dp[j][k + 200] += (dp[i][k + 200] + 1);
for (i = 0; i < len; i++)
for (k = 0; k <= 400; k++)
res += dp[i][k];
printf("%d", res);
system("pause");
return 0;
}