状态压缩DP
考试时由于24*2^24 复杂度太高没写
结果答案居然就是这样
不过枚举时要直接用lowbit(i),返回min(2^k) (i)2 第k位为1
大家直接看答案就行了
忽然发现几乎没做过状压DP的题
#include#include #include #include #include #include #include #include #include #include using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Rep(i,n) for(int i=0;i =0;i--)#define MEM(a) memset(a,0,sizeof(a))#define MEMI(a) memset(a,127,sizeof(a))#define MEMi(a) memset(a,128,sizeof(a))#define INF (2139062143)#define F (1000000007)#define MAXN (1<<24)#define MAXItem (24+10)typedef long long ll;int n,k;ll f[MAXN]={0},g[MAXN]={0},A[MAXN]={0},a[MAXItem]={0},b[MAXItem]={0};int main(){// freopen("CF327E.in","r",stdin); scanf("%d",&n); For(i,n) scanf("%d",&a[i]),A[1< >k; For(i,k) scanf("%d",&b[i]);Fork(i,k+1,2) b[i]=-1; //除了x=-1,x^-1!=0 Rep(i,1<