QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#71853 | #1769. 括号序列 | He_Ren | 100 ✓ | 206ms | 6760kb | C++17 | 1.2kb | 2023-01-12 02:00:32 | 2023-01-12 02:02:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e2 + 5;
const int mod = 1e9 + 7;
inline void add_mod(int &a,int b){ a+=b; if(a>=mod) a-=mod;}
int n,d;
char s[MAXN];
int f[MAXN][MAXN], dp[MAXN][MAXN], dp2[MAXN][MAXN];
inline bool chk(int x){ return s[x] == '*' || s[x] == '?';}
inline bool chk(int l,int r)
{
if(r-l+1 > d) return 0;
for(int i=l; i<=r; ++i)
if(!chk(i)) return 0;
return 1;
}
int main(void)
{
// freopen("bracket.in","r",stdin);
// freopen("bracket.out","w",stdout);
scanf("%d%d%s",&n,&d,s+1);
for(int i=n; i>=1; --i)
for(int j=i+1; j<=n; ++j)
{
if(s[i] != '*' && s[j] != '*' && s[i] != ')' && s[j] != '(')
{
if(chk(i+1, j-1)) f[i][j] = 1;// (), (S)
add_mod(f[i][j], dp2[i+1][j-1]);// (A), (SA)
for(int k=j-1; k>i && j-k<=d && chk(k); --k)
add_mod(f[i][j], dp[i+1][k-1]);// (AS)
dp[i][j] = f[i][j];
for(int k=i; k<j; ++k)
dp[i][j] = (dp[i][j] + (ll)f[i][k] * dp2[k+1][j]) %mod;// AB, ASB
}
dp2[i][j] = dp[i][j];
for(int k=i; k<j && k-i+1<=d && chk(k); ++k)
add_mod(dp2[i][j], dp[k+1][j]);
}
printf("%d",dp[1][n]);
return 0;
}
詳細信息
Test #1:
score: 5
Accepted
time: 2ms
memory: 5832kb
input:
14 3 ???*?(*????)??
output:
600
result:
ok single line: '600'
Test #2:
score: 5
Accepted
time: 1ms
memory: 5636kb
input:
15 7 ?()??)???*?????
output:
1443
result:
ok single line: '1443'
Test #3:
score: 5
Accepted
time: 1ms
memory: 5616kb
input:
15 10 ??*??????????(?
output:
7801
result:
ok single line: '7801'
Test #4:
score: 5
Accepted
time: 2ms
memory: 3768kb
input:
38 6 ?(????(??*??????*????*????(?(*(??*????
output:
804755392
result:
ok single line: '804755392'
Test #5:
score: 5
Accepted
time: 2ms
memory: 5756kb
input:
39 17 ?????*???)????(????*????????????*???)??
output:
734493810
result:
ok single line: '734493810'
Test #6:
score: 5
Accepted
time: 0ms
memory: 5888kb
input:
40 2 ?*???(???(?*???))??*????*???*??**(???(??
output:
946388230
result:
ok single line: '946388230'
Test #7:
score: 5
Accepted
time: 2ms
memory: 5708kb
input:
40 11 ?????*????????)??(??)?(??????*??????????
output:
513756777
result:
ok single line: '513756777'
Test #8:
score: 5
Accepted
time: 3ms
memory: 5664kb
input:
40 26 ????)????????*????????????*?????????()??
output:
156637450
result:
ok single line: '156637450'
Test #9:
score: 5
Accepted
time: 2ms
memory: 4200kb
input:
95 3 ???)??????????)?????????*???????????(?(???????????()?????(???????**??????(??*??????????***?????
output:
267516104
result:
ok single line: '267516104'
Test #10:
score: 5
Accepted
time: 3ms
memory: 4356kb
input:
98 22 ?*??????*???)??????(??)?)????????*??????????(?????))??????*????????????*****?????***????(???????*?
output:
641483452
result:
ok single line: '641483452'
Test #11:
score: 5
Accepted
time: 3ms
memory: 5872kb
input:
99 15 ???*????*??)??)??????(????**????(???*??????*??????*???)????*???????**?????????*????????*?*??????)??
output:
195466063
result:
ok single line: '195466063'
Test #12:
score: 5
Accepted
time: 3ms
memory: 4216kb
input:
100 17 ???*????(???????*?????(??(??????*???????*???????*?????)??)?????(??????*??????(????*????*???*)????*??
output:
695865604
result:
ok single line: '695865604'
Test #13:
score: 5
Accepted
time: 3ms
memory: 4352kb
input:
100 33 ??(???*????)??)????)????????????*?????**????????????*???????????*????????*?*???????))???????*?????)?
output:
114367997
result:
ok single line: '114367997'
Test #14:
score: 5
Accepted
time: 183ms
memory: 6492kb
input:
497 238 ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
211791029
result:
ok single line: '211791029'
Test #15:
score: 5
Accepted
time: 206ms
memory: 6760kb
input:
500 463 ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
572342110
result:
ok single line: '572342110'
Test #16:
score: 5
Accepted
time: 86ms
memory: 6432kb
input:
491 88 ???????????*?????????????*??????*?????*?????***?????*?????????*?????(??**??????????????*??***????????????????*?????????)*????????????????(*????????????????*?*????????????(??????*???????????*??????????*????*?*????????*???????????*?????*??????????*???????*??????**???????*???*???????????????????...
output:
617614760
result:
ok single line: '617614760'
Test #17:
score: 5
Accepted
time: 89ms
memory: 6708kb
input:
498 135 ?*?????????????*?????*??*??????*?????????**?*??*?**??*????*?????????????????????????????????*????**???????????*????*????*????*?????*????????????(()?*????????*???(?*???????????????*????????????*?????????????????????????(??*??(????)???*????)????)*???????????*???????(???????**????????????*?????...
output:
637064892
result:
ok single line: '637064892'
Test #18:
score: 5
Accepted
time: 115ms
memory: 6716kb
input:
500 174 ??*????(((*???????????????????????*???*???????*???*?????????????*??*?*??**?????(???(??????????????????*)?????????????(????????*????*????*????????????????????*?????????*??????*???*??????????????*?????????????????*???*???????????????????????????????????*?*????????????????????????????*??*??????...
output:
835939342
result:
ok single line: '835939342'
Test #19:
score: 5
Accepted
time: 121ms
memory: 6608kb
input:
500 221 ????????????*?*??*?????????*???*??????*(???)???)????(?*?????(??**??*???*??????????*??*?*???????*??????*???????*?????)????*???)??)??*??????????????????*???*???????????????????*????????**????????*?????????*??????*??*?*??????????????????*?*????????*???*??????????*????????????*???????????????*??...
output:
977731606
result:
ok single line: '977731606'
Test #20:
score: 5
Accepted
time: 135ms
memory: 6520kb
input:
500 316 ???*?*?????*???*???(??????????????*????(?????????????????*?????????????????????*???????????*??**??????*????????????????*????)???*????????????*?*????????????????????????*?*??*?????????????????????*?????????**?*???**???*????*?????????????????????????????????????*???????*??????????*?**????????*...
output:
875239106
result:
ok single line: '875239106'
Extra Test:
score: 0
Extra Test Passed