版本比较
题解:P9047 [PA 2021] Poborcy podatkowi
正文
增加 2 行删除 2 行
26 行未改动27282930313132333435363738394041414243444518 行未改动26 行未改动 val[y]=w,dfs(y,x),v.push_back(y); } shuffle(v.begin(),v.end(),rnd); int L=B,R=B,c=v.size()/2+1; for(int i=0;i<B*2;++i) for(int j=0;j<2;++j) g[i][j]=-inf; g[B][0]=0; for(int i=0;i<B*2;++i) for(int j=0;j<2;++j) g[i][j]=-inf; g[B][0]=0; for(auto y:v){ for(int j=L-1;j<=R+1;++j) h[j][0]=h[j][1]=-inf; for(int j=L;j<=R;++j){ for(int k=0;k<2;++k){ if(g[j][k]>-inf){ h[j][k^1]=max(h[j][k^1],g[j][k]+f[y][2]); h[j+1][k]=max(h[j+1][k],g[j][k]+f[y][3]); h[j][k]=max(h[j][k],g[j][k]+f[y][0]); h[j-1][k]=max(h[j-1][k],g[j][k]+f[y][1]); } } } } L=max(L-1,max(B-c,0)),R=min(R+1,min(B+c,B*2)); for(int j=L;j<=R;++j) g[j][0]=h[j][0],g[j][1]=h[j][1];18 行未改动