Topic Link: Click to open the link
Title Description: Give the number of N, to extract some number from the N number (at least one) is different from each other or after the number of programs greater than M?
Problem Solving ideas: analysis due to n<=40&&m<=10^6, so we can enumerate all possible XOR values, time complexity 40*10^6.
Using the idea of dynamic programming dp[i&1][j]=d[(I-1) &1][j]+d[(i-1) &1][j^a[i]]; because 40*10^6 is too big, so here we take a scrolling array
Code:
#include <cstdio> #include <cstring>using namespace Std;const int Maxn=1<<20;long long dp[2][maxn+10] ; int D[41];int N,m;int main () { int T; scanf ("%d", &t); for (int t=1;t<=t;++t) { scanf ("%d%d", &n,&m); for (int i=1;i<=n;++i) scanf ("%d", &d[i]); Memset (Dp,0,sizeof (DP)); Dp[0][0]=1; for (int i=1;i<=n;++i) {for (int j=0;j<maxn;++j) dp[i&1][j]=dp[(i-1) &1][j]+dp[(i-1) &1][ J^d[i]]; } Long long ans=0; int x=n&1; for (int i=m;i<maxn;i++) ans+=dp[x][i]; printf ("Case #%d:%i64d\n", T,ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
hdu5119 Happy Matt Friends (DP)