Educational Codeforces Round 83 (Rated for Div. 2)E(区间DP)
Posted ldudxy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 83 (Rated for Div. 2)E(区间DP)相关的知识,希望对你有一定的参考价值。
1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 int a[507]; 5 int dp[507]; 6 int main(){ 7 ios::sync_with_stdio(false); 8 cin.tie(NULL); 9 cout.tie(NULL); 10 int n; 11 cin>>n; 12 for(int i=1;i<=n;++i) 13 cin>>a[i]; 14 for(int i=1;i<=n;++i){ 15 stack<int>s; 16 s.push(a[i]); 17 dp[i]=dp[i-1]+1; 18 for(int j=i-1;j;--j){ 19 int num=a[j]; 20 while(!s.empty()&&s.top()==num){ 21 s.pop(); 22 ++num; 23 } 24 s.push(num); 25 dp[i]=min(dp[i],dp[j-1]+(int)s.size()); 26 } 27 } 28 cout<<dp[n]; 29 return 0; 30 }
以上是关于Educational Codeforces Round 83 (Rated for Div. 2)E(区间DP)的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 7 A
Educational Codeforces Round 7
Educational Codeforces Round 90
Educational Codeforces Round 33