正文
增加 17 行删除 17 行
29 行未改动303132333435363738394023 行未改动64656667686970717273747576777879808182838485868788899091929394959697989910094 行未改动19519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223391 行未改动32532632732832933033133233334 行未改动29 行未改动inline long long min(long long x,long long y){return x<y?x:y;}inline int abs(int x){return x>0?x:-x;}int a[35010],b[35010];long long sum1[35010],sum2[35010];int le[35010];//每个数最长的以其结尾的不下降子序列长度long long dp[35010];int lin[35010],ln;//算最长不下降子序列所用序列vector<int> v[35010];int main(){int n;23 行未改动le[i]=pl+1;}}cout<<n-ln<<endl;//第一问结束v[0].push_back(0);b[0]=-200000;//虚拟b(0)le[n+1]=ln+1;b[n+1]=200000;dp[n+1]=inf;//虚拟b(n+1)for (int j=1;j<=n+1;++j)//枚举jfor (int p=0;p<v[le[j]-1].size();++p){int i=v[le[j]-1][p];//枚举iif (i>j||b[i]>b[j])continue;sum1[i]=sum2[j]=0;for (int q=i+1;q<j;++q)sum1[q]=sum1[q-1]+abs(b[q]-b[i]);for (int q=j-1;q>i;--q)sum2[q]=sum2[q+1]+abs(b[q]-b[j]);//两个前缀和long long ans=inf;for (int k=i;k<j;++k)ans=min(ans,sum1[k]+sum2[k+1]);dp[j]=min(dp[j],dp[i]+ans);}cout<<dp[n+1];//第二问结束return 0;}```94 行未改动a[i] = b[i];}return ;}if (pos - 2 > 0 && now[pos - 2] == 'W' && now[pos - 1] == 'B')//白子跳一格{b[step + 1] = pos - 2;now[pos - 2] = ' ';now[pos] = 'W';dfs(step + 1,pos - 2);b[step + 1] = 0;//回溯now[pos - 2] = 'W';now[pos] = ' ';}if (pos - 1 > 0 && now[pos - 1] == 'W')//白子挪一格{b[step + 1] = pos - 1;now[pos - 1] = ' ';now[pos] = 'W';dfs(step + 1,pos - 1);b[step + 1] = 0;now[pos - 1] = 'W';now[pos] = ' ';}if (pos + 1 <= n * 2 + 1 && now[pos + 1] == 'B')//黑子挪一格{b[step + 1] = pos + 1;now[pos + 1] = ' ';now[pos] = 'B';dfs(step + 1,pos + 1);b[step + 1] = 0;now[pos + 1] = 'B';now[pos] = ' ';}if (pos + 2 <= n * 2 + 1 && now[pos + 2] == 'B' && now[pos + 1] == 'W')//黑子跳一格{b[step + 1] = pos + 2;now[pos + 2] = ' ';now[pos] = 'B';91 行未改动inline ll mul(ll a,ll b){ll R=0;while(b){if(b&1)R+=a,R%=mod;a+=a;b>>=1;a%=mod;}return R;}struct matrix{34 行未改动29 行未改动303132333435363738394023 行未改动64656667686970717273747576777879808182838485868788899091929394959697989910094 行未改动19519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223391 行未改动32532632732832933033133233334 行未改动29 行未改动inline long long min(long long x,long long y){return x<y?x:y;}inline int abs(int x){return x>0?x:-x;}int a[35010],b[35010];long long sum1[35010],sum2[35010];int le[35010];//每个数最长的以其结尾的不下降子序列长度long long dp[35010];int lin[35010],ln;//算最长不下降子序列所用序列vector<int> v[35010];int main(){int n;23 行未改动le[i]=pl+1;}}cout<<n-ln<<endl;//第一问结束v[0].push_back(0);b[0]=-200000;//虚拟b(0)le[n+1]=ln+1;b[n+1]=200000;dp[n+1]=inf;//虚拟b(n+1)for (int j=1;j<=n+1;++j)//枚举jfor (int p=0;p<v[le[j]-1].size();++p){int i=v[le[j]-1][p];//枚举iif (i>j||b[i]>b[j])continue;sum1[i]=sum2[j]=0;for (int q=i+1;q<j;++q)sum1[q]=sum1[q-1]+abs(b[q]-b[i]);for (int q=j-1;q>i;--q)sum2[q]=sum2[q+1]+abs(b[q]-b[j]);//两个前缀和long long ans=inf;for (int k=i;k<j;++k)ans=min(ans,sum1[k]+sum2[k+1]);dp[j]=min(dp[j],dp[i]+ans);}cout<<dp[n+1];//第二问结束return 0;}```94 行未改动a[i] = b[i];}return ;}if (pos - 2 > 0 && now[pos - 2] == 'W' && now[pos - 1] == 'B')//白子跳一格{b[step + 1] = pos - 2;now[pos - 2] = ' ';now[pos] = 'W';dfs(step + 1,pos - 2);b[step + 1] = 0;//回溯now[pos - 2] = 'W';now[pos] = ' ';}if (pos - 1 > 0 && now[pos - 1] == 'W')//白子挪一格{b[step + 1] = pos - 1;now[pos - 1] = ' ';now[pos] = 'W';dfs(step + 1,pos - 1);b[step + 1] = 0;now[pos - 1] = 'W';now[pos] = ' ';}if (pos + 1 <= n * 2 + 1 && now[pos + 1] == 'B')//黑子挪一格{b[step + 1] = pos + 1;now[pos + 1] = ' ';now[pos] = 'B';dfs(step + 1,pos + 1);b[step + 1] = 0;now[pos + 1] = 'B';now[pos] = ' ';}if (pos + 2 <= n * 2 + 1 && now[pos + 2] == 'B' && now[pos + 1] == 'W')//黑子跳一格{b[step + 1] = pos + 2;now[pos + 2] = ' ';now[pos] = 'B';91 行未改动inline ll mul(ll a,ll b){ll R=0;while(b){if(b&1)R+=a,R%=mod;a+=a;b>>=1;a%=mod;}return R;}struct matrix{34 行未改动