版本比较
1/27 YZ第十六次摸底考试题目与代码
正文
增加 17 行删除 17 行
29 行未改动3031323334343536363738394023 行未改动6465666768696869707172737475767475767778797980818282838485868788898889909192939495969697989910094 行未改动19519619719819919920020120220320420520620720820920921021121221321421521621721821921922022122222322422522622722822922923023123223391 行未改动32532632732832932933033133233334 行未改动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];//每个数最长的以其结尾的不下降子序列长度 int le[35010];//每个数最长的以其结尾的不下降子序列长度long long dp[35010];int lin[35010],ln;//算最长不下降子序列所用序列 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)//枚举j dp[n+1]=inf;//虚拟b(n+1)
for (int j=1;j<=n+1;++j)//枚举j for (int p=0;p<v[le[j]-1].size();++p) { int i=v[le[j]-1][p];//枚举i int i=v[le[j]-1][p];//枚举i if (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')//白子跳一格 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')//白子挪一格 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')//黑子挪一格 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')//黑子跳一格 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; a+=a;b>>=1;a%=mod; } return R;}struct matrix{34 行未改动