求调
查看原帖
求调
1379856
error_kkksc03楼主2024/11/21 20:56
#include <bits/stdc++.h>
#define iinf 0x3f3f3f3f
#define ll long long
#define u unsigned
#define llinf 0x3f3f3f3f3f3f3f3f
#define M map
#define _p pair
#define _ first
#define __ second
#define _q queue
#define dq deque
#define fen rand()
#define xiao srand(time(0))
#define P 1000000007
#define tu cout << rand()
#define zong cout << rand() % P
#define hashp 1825357
using namespace std;
int n;
string s; 
const int Px = 10007;
int ans;
int q(int p){
	if(p == 0)return 1;
	if(p & 1)return (2 * q(p / 2) * q(p / 2)) % Px;
	return (q(p / 2) * q(p / 2)) % Px;
}
int bet(int l,int r,int will){
	if(l > r)return 1;
	if(s[l] == '(' && s[r] == ')')return bet(l + 1,r - 1,will);
	else{
		int b = 0;
		for(int i = r;i>=l;i--){
			if(s[i] == ')')b++;
			if(s[i] == '(')b--;
			if(s[i] == '+' && !b){
				if(will)
					return (bet(l,i - 1,1) * bet(i + 1,r,0) % Px + bet(l,i - 1,1) * bet(i + 1,r,1) %Px + bet(l,i - 1,0) * bet(i + 1,r,1) % Px)%Px;
				return bet(l,i - 1,0) * bet(i + 1,r,0) % Px;
			}
		}	
		b = 0;
		for(int i = r;i>=l;i--){
			if(s[i] == ')')b++;
			if(s[i] == '(')b--;
			if(s[i] == '*' && !b){
				if(!will)
					return (bet(l,i - 1,0) * bet(i + 1,r,1) % Px + bet(l,i - 1,0) * bet(i + 1,r,0) % Px + bet(l,i - 1,1) * bet(i + 1,r,0) % Px)%Px;
				return bet(l,i - 1,1) * bet(i + 1,r,1) % Px;
			}
		}	
	}
	return 1;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n;
	cin >> s;
	ans = bet(0,n - 1,0) % Px;
	cout << ans;
	return 0;
}

最nb的是我不仅T了,还WA了。

就看看哪里WA就行。

2024/11/21 20:56
加载中...