Description, a medical team with state-of-the-art equipment and drugs, came to an African country in the Ebola virus epidemic area. There are n villages in the country, all located next to the country's only road, and N villages are sequentially labeled as,... N. The first village has a_i infected with Ebola. The first morning after arrival, the medical team was in the 1th village. Every day they can choose to treat villagers in their villages so that all infected people will heal; they can also choose to travel to a neighboring village, which takes 1 days. At the end of each day, if the a_i infected in the first village are not healed, they will die and another a_i will be infected. In other words, if the first village is not treated, the village will die every day a_i individuals. The medical team may choose not to treat the village and go to the next village I+1 when passing through village I. But in order not to let the villagers lose hope, if the medical team in the village J decided to go back, they will treat village J before all the villages were not treated, and in the process of return, if the village is not treated, they need to stop for treatment. The medical team will eventually heal all the villagers. As a team leader, you need to arrive at the minimum number of deaths in a reasonably planned itinerary.
Input
The first behavior is a positive integer n, which represents the number of villages. The next line is n positive integers a_i (1<=a_i<=10^9), the number of infections per village
Output
Output An integer that represents the minimum number of deaths before all villagers are cured.
Sample INPUT6
1 2 10Sample Output1950hint
100% of data, n<=3000
The g[i][j] means to walk from J, walk to I, then turn back to J,i to J. The smallest death toll in the village is clearly g[i][i]=0 consider whether the village was first treated or skipped so g[i][j]=g[i][j+1]+sum[j+1,i]+min ( I-J) *3*a[j],sum[j+1,i]) and then set F[i] to go to I, and the previous is cured, the total minimum number of deaths transferred is enumerated J, considering from J+1 to I, then back to J+1, then back to I that f[i]=min{f[j]+g[i] [J+1]+sum[i+1,n]* ((I-J) *4-2)} complexity O (n2) PS: This is also jsoi2016r2d2t1code:
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 using namespacestd;7typedefLong LongInt64;8 Charch;9 BOOLOK;Ten voidReadint&x) { One for(ok=0, Ch=getchar ();! IsDigit (CH); Ch=getchar ())if(ch=='-') ok=1; A for(x=0; isdigit (ch); x=x*Ten+ch-'0', ch=GetChar ()); - if(OK) x=-x; - } the voidRead (Int64 &x) { - for(ok=0, Ch=getchar ();! IsDigit (CH); Ch=getchar ())if(ch=='-') ok=1; - for(x=0; isdigit (ch); x=x*Ten+ch-'0', ch=GetChar ()); - if(OK) x=-x; + } - Const intmaxn=3005; + intN; A Int64 A[MAXN],SUM[MAXN],G[MAXN][MAXN],F[MAXN]; atinline Int64 s (intLintR) {returnsum[r]-sum[l-1];} - intMain () { - read (n); - for(intI=1; i<=n;i++) read (A[i]); - for(intI=1; i<=n;i++) sum[i]=sum[i-1]+A[i]; - for(intI=1; i<=n;i++){ ing[i][i]=0; - for(intj=i-1; j>=1; j--) g[i][j]=g[i][j+1]+s (j+1, i) +min (3ll* (i-j) *a[j],s (j+1, i)); to } +Memset (F, the,sizeof(f)); -f[0]=0; the for(intI=1; i<=n;i++) for(intj=0; j<i;j++) F[i]=min (f[i],f[j]+g[i][j+1]+s (i+1, N) * (4ll* (I-J)-2)); *printf"%lld\n", F[n]); $ return 0;Panax Notoginseng}
bzoj4038: Medical Assistance