hdu5119 Happy Matt Friends (DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.