"topic analysis" in a set of numbers whether there is n number, so that the sum of n is equal to a given value m.
"Thinking Analysis": Analysis of data in the case:
1): 0 < n <= 100000
2): 0 < sequence length <= 100000
3): 0 <= m <=100000
Data is small: with a similar idea of DP,
Code:
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream>using namespace STD; #define REP (i,j,k) for (int i= (int) j;i< (int.) k;++i) #define PER (i,j,k) for (int i= (int) j;i> (int) k;--i) #define Lowbit (a) A&-a#define Max (A, B) a>b?a:b#define Min (A, B) a>b?b:a#define mem (A, B) memset (A,b,sizeof (a)) typedef Long long ll;typedef unsigned long long llu;typedef double db;const int n=1e5+10;const int inf=0x3f3f3f3f;int t,n,m;int PR E[n],last[n];int Num[n];int Main () {int x=0; Char ch; int sum=1; MEM (last,0); while (~ (Ch=getchar ())) {if (IsDigit (CH)) x=x*10+ch-' 0 '; else if (ch!= ' \ n ') {pre[sum++]=x; x=0; } else{pre[sum++]=x; MEM (last,0); Last[0]=1; M=read (); for (int i=1, i<sum; ++i) {for (int j=m; j>=0;--j) {int k=pre[i]+j; if (last[j]&&k<=m) last[k]=1; cout<< "k=" <<k<< "<<" Last[k "<<last[k]<<endl; }} if (Last[m]) puts ("Yes"); Else puts ("No"); x=0; Sum=1; MEM (last,0); }} return 0;}
The number of n in a set of numbers, so that the sum of n equals a given value M