标签:blog io for sp 2014 c log amp r
//连续的和的绝对值最小 # include <stdio.h> # include <string.h> # include <algorithm> # include <math.h> using namespace std; int main() { int t,i,j,num,n,min1; int sum[1010],a[1010]; int cas=0; while(~scanf("%d",&t)) { while(t--) { scanf("%d",&n); for(i=0; i<n; i++) scanf("%d",&a[i]); min1=999999999; for(i=0; i<n; i++) { sum[i]=abs(a[i]); num=a[i]; for(j=i-1; j>=0; j--) { num=num+a[j]; if(sum[i]>abs(num)) sum[i]=abs(num); } if(min1>sum[i]) min1=sum[i]; } printf("Case %d: %d\n",++cas,min1); } } return 0; }
hdu 4223 Dynamic Programming? (dp)
标签:blog io for sp 2014 c log amp r
原文地址:http://blog.csdn.net/lp_opai/article/details/39721763