思路1:
右键在新窗口打开图片
代码:
#includeusing namespace std;#define ll long long#define pb push_back#define mem(a,b) memset(a,b,sizeof(a))int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; int ans=0; for(int i=0;i 0&&q>score)q--,score++; if(score<0)break; if((j-i+1)%2==0&&q>=score)ans++; } } cout< <
思路2:
结论:
证明见
代码:
#includeusing namespace std;#define ll long long#define pb push_back#define mem(a,b) memset(a,b,sizeof(a))const int N=5e3+5;int cnt[N][N];int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; int ans=0; for(int i=0;i l)break; cnt[i][j]++; } } for(int i=0;i =0;j--){ if(s[j]==')'||s[j]=='?')r++; else l++; if(l>r)break; cnt[j][i]++; } } for(int i=0;i