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)