In fact, the DP of the subset class, generally this DP we just need a one-dimensional scrolling array can be, but this problem is not only the state of transition can be backward and possible forward, so this time with a two-dimensional array.
State equation Dp[i][j]=dp[i-1][j]+dp[i-1][j^num[i]], respectively, indicating the number of the first and the number of I and the status of the case.
The code is as follows:
#include <iostream>#include <cstdio>#include <cstring>using namespace STD;#define MAXN 2100000/// too small will WA intdp[ -][MAXN];intnum[ -];intMain () {intT,case=0;scanf("%d", &t); while(t--) {intN,m;memset(DP,0,sizeof(DP));scanf("%d%d", &n,&m); for(intI=1; i<=n;i++)scanf("%d", &num[i]);intMax= (1<< -); dp[0][0]=1;/// use J^NUM[I]^NUM[I]=J for state transfer /// i.e. dp[i-1][j] [dp[i-1][j^num[i]] ^num[i] ///dp[i][j]=dp[i-1][j]+dp[i-1][j^num[i]] for(intI=1; i<=n;i++) { for(intj=0; j<=max;j++) dp[i][j]=dp[i-1][j]+dp[i-1][j^num[i]]; }Long Longsum=0; for(inti=m;i<=max;i++) Sum+=dp[n][i];printf("Case #%d:%lld\n", ++case,sum); }return 0;}
Hdu--5119happy Matt FRIENDS+DP