标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 18680 | Accepted: 10075 |
Description
Input
Output
Sample Input
10 5 1 2 3 6 7 9 11 22 44 50
Sample Output
9
Source
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int V=305,P=35,INF=1e9; inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } int v,p,a[V],l[V][V],f[V][P]; void dp(){ for(int i=1;i<=v;i++) for(int j=i+1;j<=v;j++) l[i][j]=l[i][j-1]+a[j]-a[(i+j)/2]; for(int i=1;i<=v;i++) for(int j=0;j<=v;j++) f[i][j]=INF,f[i][1]=l[1][i]; for(int i=1;i<=v;i++) for(int j=1;j<=p;j++){ for(int k=1;k<i;k++) f[i][j]=min(f[i][j],f[k][j-1]+l[k+1][i]); } } int main(int argc, const char * argv[]) { v=read();p=read(); for(int i=1;i<=v;i++)a[i]=read(); dp(); printf("%d",f[v][p]); return 0; }
标签:
原文地址:http://www.cnblogs.com/candy99/p/5828004.html