" topic link ": Click here~~
"The main topic "
The number of a group of topics (N<=15), each topic has corresponding difficulty, asked you to choose a certain topic (more than R and less than L) and the choice of the topic of the minimum difficulty and the maximum difficulty difference is not less than X, the choice of the number of options.
" problem-solving ideas ":
dfs+ backtracking.
First send a rather clumsy code:
#include <bits/stdc++.h>using namespace Std;const int n=1e5+10;int num[n],mum[n];int n,m,q,t,l,r;int top,ans,cnt ; void Dfs (int sum,int d,int x,int minn)///And, extremum, current loop, minimum number { if (sum>=l&&sum<=r&&d>=q) ans++ ; if (sum>r) return; if (sum<l) return, the current cumulative sum may be less than L for (int i=x;i<=n;++i) { dfs (Sum+num[i],num[i]-minn,i+1,minn) ; }} int main () { while (cin>>n>>l>>r>>q) { ans=0; memset (num,0,sizeof (num)); for (int i=1; i<=n; ++i) scanf ("%d", &num[i]); Sort (num+1,num+1+n); for (int i=1; i<=n; ++i) { dfs (num[i],0,i+1,num[i]);///to refer to maximum and minimum, introduce the minimum number } printf ("%d\n", ans) ; } return 0;}
Codeforces 550B Preparing Olympiad (Dfs backtracking)