luogu3146 [USACO16OPEN]248

细节被坑惨

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=1e6+5;
 4 const int INF=1e9+7;
 5 int n,ans,dp[305][305];
 6 template <class t>void red(t &x)
 7 {
 8     x=0;
 9     int w=1;
10     char ch=getchar();
11     while(ch<'0'||ch>'9')
12     {
13         if(ch=='-')
14             w=-1;
15         ch=getchar();
16     }
17     while(ch>='0'&&ch<='9')
18     {
19         x=(x<<3)+(x<<1)+ch-'0';
20         ch=getchar();
21     }
22     x*=w;
23 }
24 void input()
25 {
26     freopen("input.txt","r",stdin);
27 }
28 void read()
29 {
30     red(n);
31     for(int i=1;i<=n;++i)
32         red(dp[i][i]); 
33 }
34 void work()
35 {
36     for(int i=1;i<=n;++i)
37         for(int j=1;j+i<=n+1;++j)
38         {
39             int e=i+j-1;
40             for(int k=j;k<e;++k)
41                 if(dp[j][k]==dp[k+1][e]) 
42                     dp[j][e]=max(dp[j][e],dp[j][k]+1);
43                 ans=max(ans,dp[j][e]);
44             //    else
45             //        dp[j][e]=max(dp[j][e],max(dp[j][k],dp[k+1][e]));
46         }
47     printf("%d",ans);
48 }
49 int main()
50 {
51     //input();
52     read();
53     work();
54     return 0;
55 }
View Code

 

转载于:https://www.cnblogs.com/Achensy/p/10804490.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值