版本比较
模拟赛放个人代码
正文
增加 31 行删除 0 行
155 行未改动全部展开156157158159155 行未改动全部展开printf("%d",dp[n]);return 0;}```155 行未改动全部展开156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190155 行未改动全部展开printf("%d",dp[n]);return 0;}```# S4 T2```#include<bits/stdc++.h>using namespace std;int n,dp[2010][2010],a[2010],l[2010],r[2010],t,N,P[2010];char s[2010],c[2010];const int mod=1e6+3;int main(){scanf("%s",s+1),n=strlen(s+1);for(int w=1;w<=n;w++)if(!(s[w]>='0'&&s[w]<='9'&&s[w-1]>='0'&&s[w-1]<='9'))c[++N]=s[w];n=N;for(int w=1;w<=n;w++)s[w]=c[w];for(int w=1;w<=n;w++)if(s[w]=='-')s[w]='+';for(int w=1;w<=n;w++)if(s[w]>='0'&&s[w]<='9')dp[w][w]=1;else if(s[w-1]>='0'&&s[w-1]<='9'&&s[w+1]!='*'&&s[w+1]!='/')a[++t]=w,l[t]=w-1,r[t]=w+1;a[t+1]=a[t+2]=a[t+3]=a[t+4]=a[t+5]=a[t+6]=1e9;for(int w=1;w<=n;w++)P[w]=upper_bound(a+1,a+t+1,w)-a;for(int L=2;L<=n;L++)for(int w=1,x=L;x<=n;w++,x++){if(s[x]<'0'||s[x]>'9'||s[w]=='*'||s[w]=='/')continue;if(s[w]=='+')dp[w][x]=dp[w+1][x];int p=P[w];long long s=0;for(;a[p+5]<x;p+=6)s+=1ll*dp[w][l[p]]*dp[r[p]][x]+1ll*dp[w][l[p+1]]*dp[r[p+1]][x]+1ll*dp[w][l[p+2]]*dp[r[p+2]][x]+1ll*dp[w][l[p+3]]*dp[r[p+3]][x]+1ll*dp[w][l[p+4]]*dp[r[p+4]][x]+1ll*dp[w][l[p+5]]*dp[r[p+5]][x];for(;a[p]<x;p++)s+=1ll*dp[w][l[p]]*dp[r[p]][x];dp[w][x]=(dp[w][x]+s)%mod;}printf("%d",dp[1][n]);return 0;}```