码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 83 (Rated for Div. 2)E(区间DP)

时间:2020-03-12 09:22:23      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:namespace   false   name   amp   stack   empty   struct   ati   lse   

 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)

标签:namespace   false   name   amp   stack   empty   struct   ati   lse   

原文地址:https://www.cnblogs.com/ldudxy/p/12466964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!