QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#114486 | #4436. Link with Bracket Sequence II | Liuf | WA | 492ms | 5276kb | C++20 | 1.0kb | 2023-06-22 10:26:59 | 2023-06-22 10:27:00 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define pii pair<int, int>
#define int long long
using namespace std;
const int mod=1e9+7;
void solve(){
int n,m;
cin>>n>>m;
vector<int>a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
vector dp(n+10,vector<int>(n+10,-1));
function<int(int,int)>dfs=[&](int l,int r){
if((r-l+1)&1)return 0ll;
if(l>r)return 1ll;
if(dp[l][r]!=-1)return dp[l][r];
int ans=0;
if(a[l]>0){
for(int i=l+1;i<=r;i+=2){
if(a[i]<0||!a[i]){
ans+=dfs(l+1,i-1)*dfs(i+1,r)%mod;
ans%=mod;
}
}
} else if(!a[l]){
for(int i=l+1;i<=r;i+=2){
if(!a[i]){
ans+=m*dfs(l+1,i-1)%mod*dfs(i+1,r)%mod;
ans%=mod;
} else if(a[i]<0){
ans+=dfs(l+1,i-1)*dfs(i+1,r)%mod;
ans%=mod;
}
}
}
return dp[l][r]=ans;
};
cout<<dfs(1,n)<<endl;
// cout<<1<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 492ms
memory: 5276kb
input:
20 10 1 1 -1 0 -1 -1 1 -1 1 0 0 10 2 0 1 1 -2 1 -2 -1 1 -2 1 8 5 0 0 4 0 0 2 -2 0 9 5 0 0 0 -3 0 0 0 0 0 8 5 0 1 0 0 0 0 0 0 498 249013689 239722195 0 0 0 -59682797 187213467 0 0 220688278 0 0 -133178217 165866643 -165866643 216987003 55229518 -55229518 -216987003 0 82546192 0 0 0 0 -62330427 -19687...
output:
0 0 75 0 1125 984267258 109218678 571952022 288159326 14438262 1 55416571 307794316 686930163 248163740 867480547 155641228 227852148 343052576 776801212
result:
wrong answer 6th lines differ - expected: '469841384', found: '984267258'