This question is DP? However, it is clear that the solution is not DP... for this class of question about finding a combination of intervals... You can first set each sum (1 ~ K) calculate... get the value of a certain range by the difference between the two sum... think of this step... the idea of this question comes out... calculate all sum (1 ~ K) <1 <= k <= n> .. sort sum .. find the smallest sum [I]-sum [I-1... but pay attention to it here .. for sum .. there should be n + 1 .. that is to add a sum [n + 1] = 0...
Program:
# Include <stdio. h> # include <iostream> # include <string. h> # include <math. h> using namespace STD; int t, t, a [1005], n, I, ans; int main () {freopen ("input.txt", "r", stdin ); freopen ("output.txt", "W", stdout); scanf ("% d", & T); For (t = 1; t <= T; t ++) {scanf ("% d", & N); for (I = 1; I <= N; I ++) scanf ("% d ", & A [I]); for (I = 2; I <= N; I ++) A [I] + = A [I-1]; A [+ N] = 0; sort (a + 1, A + 1 + n); ans = 200000; for (I = 2; I <= N; I ++) if (ANS> A [I]-A [I-1]) ans = A [I]-A [I-1]; printf ("case % d: % d \ n ", T, ANS);} return 0 ;}