CF1463F Max Correct Set

考虑证明一个答案必定为((x + y))的循环节递归。

考虑到如果第二块比第一块答案大,则必定可以把第一块换为第二块增加答案。
且可以证明,如果((x + y))是合法的,则整个序列合法。

那我们只要做出第一个循环节的dp,并考虑剩下的零散点的取值即可。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
int n,x,y,m,t,f[2][1<<22],ans;
inline void cmax(int &x,int y){if(y>x)x=y;}
int main(){
	scanf("%d%d%d",&n,&x,&y);
	m = x + y , t = 1 << 22;
	memset(f[0],0xcf,sizeof(f[0]));
	f[0][0] = 0;
	rep(i,1,m){
		int op = i & 1;
		memset(f[op],0xcf,sizeof(f[op]));
		rep(j,0,t-1){
			cmax(f[op][(t-1)&(j<<1)],f[op^1][j]);
			if(1 & (j >> (x - 1)))continue;
			if(1 & (j >> (y - 1)))continue;
			cmax(f[op][1^((t-1)&(j<<1))],f[op^1][j]+n/m+(n%m>=i));
		}
		rep(j,0,t-1)cmax(ans,f[op][j]);
	}
	printf("%d
",ans);
	return 0;
}
原文地址:https://www.cnblogs.com/dixiao/p/15216378.html