nyoj1189 Yougth and his friends (rolling array use)

Source: Internet
Author: User

Yougth and his friends time limit:10000Ms | Memory Limit:65535KB Difficulty:3
Describe
Yougth's friends each have a magical value of X, and now Yougth want to pick out some of these friends so that the magic value of these friends is equal to or greater than M. How many of these combinations are there?
Input
multiple sets of data
Each group of data first two numbers n and m, indicating the number of friends and the value to be greater than equals, ((1≤n≤40, 0≤m≤10^6)
The next n number represents each person's Mana value x (0≤x≤10^6)
Output
outputs the number of scenarios that meet the criteria
Sample input
3 21 2 33 31 2 3
Sample output
42
Tips
The
first example
1^2 = 3
1^3 = 2
2
3

A total of four meet the conditions, so direct output 4

Idea: Define DP[I][J] to get I put in after the J program number

DP[I][J]=DP[I-1[J]+DP[I-1][J];

Because the data is a little big look at the next Younth blog found to use the scroll array optimization

Also, it is important to note that the data after RE is 1048000 or later may exceed the range of the array (kneeling cry)


#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;long Long dp[2][1200005];int a[45];int main () {    int n,m,i,j;    while (~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<1048576; j + +)//            {                dp[i%2][j]=dp[(i-1)%2][j]+dp[(i-1)%2][j^a[i] ];            }        A long long ans = 0;        for (i=m;i<1048576;i++)            ans+=dp[n%2][i];        printf ("%lld\n", ans);}    }


nyoj1189 Yougth and his friends (rolling array use)

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.