POJ2955

匹配则加一,不需要初始化

 1 //#include<bits/stdc++.h>
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<vector>
 6 #include<cstring>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<bitset>
11 #include<utility>
12 #include<functional>
13 #include<iomanip>
14 #include<sstream>
15 #include<ctime>
16 #include<cassert>
17 #define a first
18 #define b second
19 #define mp make_pair
20 #define pb push_back
21 #define pw(x) (1ll << (x))
22 #define sz(x) ((int)(x).size())
23 #define all(x) (x).begin(),(x).end()
24 #define rep(i,l,r) for(int i=(l);i<(r);i++)
25 #define per(i,r,l) for(int i=(r);i>=(l);i--)
26 #define FOR(i,l,r) for(int i=(l);i<=(r);i++)
27 #define debug1(a)\
28 cout << #a << " = " << a << endl;
29 #define debug2(a,b)\
30 cout << #a << " = " << a << endl;\
31 cout << #b << " = " << b << endl;
32 #define debug3(a,b,c)   cout << #a << " = " << a << endl;\
33 cout << #b << " = " << b << endl;\
34 cout << #c << " = " << c << endl;
35 #define debug4(a,b,c,d)\
36 cout << #a << " = " << a << endl;\
37 cout << #b << " = " << b << endl;\
38 cout << #c << " = " << c << endl;\
39 cout << #d << " = " << d << endl;
40 #define debug5(a,b,c,d,e)\
41 cout << #a << " = " << a << endl;\
42 cout << #b << " = " << b << endl;\
43 cout << #c << " = " << c << endl;\
44 cout << #d << " = " << d << endl;\
45 cout << #e << " = " << e << endl;
46 #define eps 1e-9
47 #define PIE acos(-1)
48 #define cl(a,b) memset(a,b,sizeof(a))
49 #define fastio ios::sync_with_stdio(false);cin.tie(0);
50 #define lson l , mid , ls
51 #define rson mid + 1 , r , rs
52 #define ls (rt<<1)
53 #define rs (ls|1)
54 #define INF 0x3f3f3f3f
55 #define lowbit(x) (x&(-x))
56 #define sqr(a) a*a
57 #define ll long long
58 #define vi vector<int>
59 #define pii pair<int, int>
60 using namespace std;
61 //**********************************
62 char s[107];
63 int n;
64 int dp[107][107];
65 //**********************************
66 bool match(int a,int b)
67 {
68     char x=s[a],y=s[b];
69     return x=='['&&y==']'||x=='('&&y==')';
70 }
71 void solve()
72 {
73     FOR(len,2,n)FOR(l,1,n-len+1){
74         int r=l+len-1;
75         dp[l][r]=dp[l+1][r-1]+match(l,r); 
76         rep(k,l,r){
77             dp[l][r]=max(dp[l][r],dp[l][k]+dp[k+1][r]);
78         }
79     }
80     printf("%d\n",dp[1][n]<<1);
81 }
82 //**********************************
83 int main()
84 {
85     while(~scanf("%s",s+1)&&s[1]!='e'){
86         n=strlen(s+1);
87         solve();
88     }
89     return 0;
90 }
View Code

相关文章:

  • 2021-09-21
  • 2022-01-01
  • 2021-08-10
  • 2022-02-02
  • 2019-09-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-25
  • 2021-06-02
  • 2021-11-26
  • 2022-12-23
相关资源
相似解决方案