正文
增加 13 行删除 13 行
7 行未改动89101112131415163 行未改动20212223242526272814 行未改动43444546474849505111 行未改动636465666768697071727374757677785 行未改动848586878889909192935 行未改动991001011021031041051061071081091101115 行未改动1171181191201211221231241254 行未改动1301311321331341351367 行未改动其中 $+$、$-$ 不满足结合律,即 $R+P+S \ne R+(P+S)$,所以要严格要求从左往右计算。根据运算要求转化为后缀表达式求解(~不转也行~),最后输出目标结果对应答案三元组中的方案数即可。```cpp#include<bits/stdc++.h> //我爱万能头using namespace std;#define int long longconst int Mod=1e9+7;struct Node{3 行未改动string s;char c,ch;stack<Node>res;stack<char>opt;Node calc(Node a,Node b,char ch){ //+、-、*运算Node res={0,0,0};if(ch=='+'){(res.r=(a.r*b.r)%Mod+(a.r*b.s)%Mod+(a.s*b.r)%Mod)%=Mod;(res.s=(a.s*b.s)%Mod+(a.s*b.p)%Mod+(a.p*b.s)%Mod)%=Mod;14 行未改动signed main(){cin>>n;cin>>s;cin>>c;s='('+s+')'; //这样好像可以确保运算完全for(int i=1;i<=n+1;i++){if(s[i]=='R'){res.push({1,0,0});}11 行未改动ch=opt.top();if(ch=='('){break;}opt.pop();a=res.top();res.pop();b=res.top();res.pop();res.push(calc(a,b,ch));}opt.push('+');}if(s[i]=='-'){while(!opt.empty()){ch=opt.top();5 行未改动res.pop();b=res.top();res.pop();res.push(calc(a,b,ch));}opt.push('-');}if(s[i]=='*'){while(!opt.empty()){ch=opt.top();5 行未改动res.pop();b=res.top();res.pop();res.push(calc(a,b,ch));}opt.push('*');}if(s[i]=='('){opt.push('(');}if(s[i]==')'){while(!opt.empty()){ch=opt.top();5 行未改动res.pop();b=res.top();res.pop();res.push(calc(a,b,ch));}}}ans=res.top();if(c=='R'){4 行未改动}if(c=='P'){cout<<ans.p;}return 0; //完结撒花}```7 行未改动89101112131415163 行未改动20212223242526272814 行未改动43444546474849505111 行未改动636465666768697071727374757677785 行未改动848586878889909192935 行未改动991001011021031041051061071081091101115 行未改动1171181191201211221231241254 行未改动1301311321331341351367 行未改动其中 $+$、$-$ 不满足结合律,即 $R+P+S \ne R+(P+S)$,所以要严格要求从左往右计算。根据运算要求转化为后缀表达式求解(~不转也行~),最后输出目标结果对应答案三元组中的方案数即可。```cpp#include<bits/stdc++.h> //我爱万能头using namespace std;#define int long longconst int Mod=1e9+7;struct Node{3 行未改动string s;char c,ch;stack<Node>res;stack<char>opt;Node calc(Node a,Node b,char ch){ //+、-、*运算Node res={0,0,0};if(ch=='+'){(res.r=(a.r*b.r)%Mod+(a.r*b.s)%Mod+(a.s*b.r)%Mod)%=Mod;(res.s=(a.s*b.s)%Mod+(a.s*b.p)%Mod+(a.p*b.s)%Mod)%=Mod;14 行未改动signed main(){cin>>n;cin>>s;cin>>c;s='('+s+')'; //这样好像可以确保运算完全for(int i=1;i<=n+1;i++){if(s[i]=='R'){res.push({1,0,0});}11 行未改动ch=opt.top();if(ch=='('){break;}opt.pop();a=res.top();res.pop();b=res.top();res.pop();res.push(calc(a,b,ch));}opt.push('+');}if(s[i]=='-'){while(!opt.empty()){ch=opt.top();5 行未改动res.pop();b=res.top();res.pop();res.push(calc(a,b,ch));}opt.push('-');}if(s[i]=='*'){while(!opt.empty()){ch=opt.top();5 行未改动res.pop();b=res.top();res.pop();res.push(calc(a,b,ch));}opt.push('*');}if(s[i]=='('){opt.push('(');}if(s[i]==')'){while(!opt.empty()){ch=opt.top();5 行未改动res.pop();b=res.top();res.pop();res.push(calc(a,b,ch));}}}ans=res.top();if(c=='R'){4 行未改动}if(c=='P'){cout<<ans.p;}return 0; //完结撒花}```