题意:
从n个数中任选一些数,问有多少种选法使他们异或和不小于M
思路:
dp[i][j]表示选i个数异或和为j,则方程dp[i][j] = dp[i-1][j](不选i)+ dp[i-1][j^a[i]]
#include#include #include #include using namespace std;typedef long long ll;const int maxn = 2e6 + 5;int dp[41][maxn];int a[41];int main(){ int T,n,m; scanf("%d",&T); int cas = 1; while(T--) { scanf("%d%d",&n,&m); for(int i = 1;i <= n;i++) { scanf("%d",&a[i]); } memset(dp,0,sizeof(dp)); dp[0][0] = 1; int Max=(1<<20); for(int i = 1;i <= n;i++) { for(int j = 0;j <= Max;j++) dp[i][j] = dp[i-1][j] + dp[i-1][j^a[i]]; } ll ans = 0; for(int i = m;i <= Max;i++) ans += dp[n][i]; printf("Case #%d: %I64d\n",cas++,ans); } return 0;}