标签:style blog http color java os io for
10 5 1 2 3 6 7 9 11 22 44 50
9
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #define LL long long 10 #define INF 0x3f3f3f3f 11 using namespace std; 12 int dp[35][301],x[301],n,m; 13 int dis(int i,int j){ 14 int sum = 0; 15 while(i < j) sum += x[j--]-x[i++]; 16 return sum; 17 } 18 int main(){ 19 int i,j,k; 20 while(~scanf("%d%d",&m,&n)){ 21 memset(dp,0,sizeof(dp)); 22 for(i = 1; i <= m; i++){ 23 scanf("%d",x+i); 24 dp[1][i] = dis(1,i); 25 } 26 for(i = 2; i <= n; i++){ 27 for(j = i; j <= m; j++){ 28 dp[i][j] = INF; 29 for(k = i-1; k < j; k++) 30 dp[i][j] = min(dp[i][j],dp[i-1][k]+dis(k+1,j)); 31 } 32 } 33 cout<<dp[n][m]<<endl; 34 } 35 return 0; 36 }
xtu summer individual 5 F - Post Office,布布扣,bubuko.com
xtu summer individual 5 F - Post Office
标签:style blog http color java os io for
原文地址:http://www.cnblogs.com/crackpotisback/p/3898285.html