Although it is a simple DP, not even the rolling array can be AC, the amount of data is not very large.
For the number of N, there are only two states for each number, taking and not taking.
It is easy to derive the state transition equation:
Dp[i][j] = dp[i-1][j ^ A[i]] + dp[i-1][j];
DP[I][J] means that for the first I number in the sequence, the XOR and the number of schemes that happen to be J
Dp[i-1][j in the state transition equation] means that the current number is not taken, Dp[i-1][j ^ A[i]] indicates that the current number is to be taken.
This problem is still to understand Ah!
Source code:
//#pragma COMMENT (linker, "/stack:16777216")//For C + + Compiler#include <stdio.h>#include<iostream>#include<cstring>#include<cmath>#include<stack>#include<queue>#include<vector>#include<algorithm>#definell Long Long#defineMax (b) ((a) > (b))? (a): (b))#defineMin (b) ((a) < (a))? (a): (b))#defineAbs (x) (((x) > 0)? (x): (-(x)))using namespacestd;Const intINF =0x3f3f3f3f;intdp[2][1<< -];inta[ A];intMain () {intI, J, K, T, N, m, numcase =0; scanf ("%d",&T); while(t--) {scanf ("%d%d",&n,&m); for(i =1; I <= N; ++i) scanf ("%d", A +i); Memset (DP,0,sizeof(DP)); dp[0][0] =1; for(i =1; I <= N; ++i) { for(j =0; J < (1<< -); ++j) {Dp[i%2][J] = dp[(i-1) %2][j ^ A[i]] + dp[(i-1) %2][j]; } } Long LongAns =0; for(i = m; I < (1<< -); ++i) {ans+ = dp[n%2][i]; } printf ("Case #%d:%i64d\n",++numcase, ans); } return 0;}
HDU 5119 Happy Matt Friends (2014 Beijing Regional Live race H-question Bare backpack DP)