HDU 4283 You Are the One 区间DP
引用某位大神的解析,解析太长懒得写,这题关键是那个小黑屋是个stack,读了一遍题愣是没看出来
http://www.tuicool.com/articles/jyaQ7n 膜拜一下
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cstdlib> #include<cmath> #include<cstdlib> #include<vector> #include<queue> using namespace std; typedef long long LL; int dp[105][105],a[105]; int sum[105]; const int INF=0x3f3f3f3f; int main() { int T,cas=0; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;++i) scanf("%d",&a[i]),sum[i]=sum[i-1]+a[i]; for(int l=1;l<n;++l) { for(int i=1;i+l<=n;++i) { int j=i+l; dp[i][j]=INF; for(int k=1;k<=l+1;++k) dp[i][j]=min(dp[i][j],dp[i+1][i+k-1]+dp[i+k][j]+a[i]*(k-1)+(sum[j]-sum[i+k-1])*k); } } printf("Case #%d: %d\n",++cas,dp[1][n]); } return 0; }