HDU 4223 Dynamic Programming?
这题虽然题意中是说。。用DP。。但是其实数据量只有1000,,,直接暴力也就过了- -
把每个区间的和求出来,然后比较绝对值,求出最小的。。即可
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int t;
int n;
int a[1005];
int min;
int main()
{
int tt = 1;
scanf("%d", &t);
while (t --)
{
memset(a, 0, sizeof(a));
scanf("%d", &n);
for (int i = 0; i < n; i ++)
{
scanf("%d", &a[i]);
}
min = 999999999;
for (int i = 0; i < n; i ++)
{
int sum = 0;
for (int j = i; j < n; j ++)
{
sum += a[j];
if (min > abs(sum))
min = abs(sum);
}
}
printf("Case %d: %d\n", tt ++, min);
}
return 0;
}