Codeforces 550B Preparing Olympiad (Dfs backtracking)

Source: Internet
Author: User

" 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)

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.