标签:bsp define names har sdi 状态 tmp lag 最大值
1 //minamoto 2 #include<bits/stdc++.h> 3 using namespace std; 4 #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) 5 char buf[1<<21],*p1=buf,*p2=buf; 6 template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;} 7 inline int read(){ 8 #define num ch-‘0‘ 9 char ch;bool flag=0;int res; 10 while(!isdigit(ch=getc())) 11 (ch==‘-‘)&&(flag=true); 12 for(res=num;isdigit(ch=getc());res=res*10+num); 13 (flag)&&(res=-res); 14 #undef num 15 return res; 16 } 17 const int N=2e6+5; 18 int n,m,sum[N],dp[N],lim; 19 int main(){ 20 // freopen("testdata.in","r",stdin); 21 n=read();for(int i=1;i<=n;++i) sum[1<<(i-1)]=read(); 22 m=read();for(int i=1;i<=m;++i) sum[1<<(i+n-1)]=-read(); 23 lim=1<<(n+m); 24 for(int i=1;i<lim;++i){ 25 int tmp=i&-i;sum[i]=sum[tmp]+sum[i-tmp]; 26 for(int j=1;j<=n+m;++j) 27 if(i&(1<<(j-1))) cmax(dp[i],dp[i-(1<<(j-1))]); 28 if(!sum[i]) ++dp[i]; 29 } 30 printf("%d\n",n+m-2*dp[lim-1]); 31 return 0; 32 }
标签:bsp define names har sdi 状态 tmp lag 最大值
原文地址:https://www.cnblogs.com/bztMinamoto/p/9787961.html