随笔 - 531  文章 - 0  评论 - 3  阅读 - 10215 

消除方块,同色可以消除,产生价值 (len)^2

求最后最大的价值

 

区间dp

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include<queue>
#include <cstring>
#define IOS std::ios::sync_with_stdio(0)
using namespace std;
 const int N =203;
 int a[N],f[N][N][N],n;
   
 int dfs(int l,int r,int m){
    int &t=f[l][r][m];
    if(~t) return t;
    if(l>r) return t=0;
     
    t=dfs(l,r-1,0)+(1+m)*(1+m);
    for(int k=l;k<r;k++){
        if(a[k]==a[r])
        t=max(t,dfs(l,k,m+1)+dfs(k+1,r-1,0));
    }
    return t;
 }
 signed main(){
    int tes,cas=0;
    cin>>tes;
     
    while(tes--){
        cin>>n;
        cout<<"Case "<<(++cas)<<": ";
        for(int i=1;i<=n;i++) cin>>a[i];
         
        memset(f,-1,sizeof f) ;
        cout<<dfs(1,n,0)<<endl;
    }
 }

 

posted on   towboat  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示