This topic I started with the idea is to use two-dimensional DP, the results of tle. Later changed a train of thought, finally AC.
There is no need to judge all the cases, we use dp[i] to represent the largest number of cows in the first I Niu Quan, and this I must first >= limit the Niu Quan tree F. Num[i] Indicates how many NIU Quan are included in Dp[i].
we can know, dp[i] = sum[i]-sum[i-f])/F or dp[i-1] + data[i], before a representative to the first F Niu Quan the number of cows, the latter represents the former i-1 Niu Quan The number of cows in the maximum number of cows + the Niu Quan in the first I. In fact, so far before I num[i-1]+1 a niu Quan cattle number. and determine which condition is judged (sum[i]-sum[i-f])/F and Dp[i-1] + data[i]/(num[i-1]+1) size.
#include <stdio.h> #include <algorithm> #define MAX (x, y) (x>y?x:y) #define MAX 100002double dp[max],data[ Max],num[max],sum[max];int Main () {int i,n,f;double maxval;scanf ("%d%d", &n,&f); for (i=1;i<=n;i++) {scanf ( "%lf", &data[i]); Sum[i] = Data[i] +sum[i-1];num[i] = f;} DP[F] = Sum[f];maxval = dp[f]*1000/f;for (i=f+1;i<=n;i++) {if ((Sum[i]-sum[i-f])/F > (Dp[i-1] + data[i])/(num[ I-1] + 1)) {Dp[i] = Sum[i]-sum[i-f];num[i] = f;} Else{dp[i] = Dp[i-1] + data[i];num[i] = num[i-1] +1;} Maxval = max (Maxval,dp[i]*1000/num[i]);} printf ("%d\n", (int) (maxval));}
POJ Dynamic Planning DP-2018 Best Cow Fences