zoukankan      html  css  js  c++  java
  • DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门

     1 /*
     2     DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return ;
     3 */
     4 #include <cstdio>
     5 #include <iostream>
     6 #include <cstring>
     7 #include <cmath>
     8 #include <algorithm>
     9 #include <vector>
    10 #include <map>
    11 #include <queue>
    12 #include <set>
    13 #include <string>
    14 #include <stack>
    15 using namespace std;
    16 
    17 typedef long long ll;
    18 const int MAXN = 1e4 + 10;
    19 const int INF = 0x3f3f3f3f;
    20 int a[20];
    21 bool vis[20];
    22 int n, l, r, x;
    23 int ans;
    24 
    25 void DFS(int sum, int cnt, int s, int p)
    26 {
    27     if (sum >= l && cnt >= 2 && a[p] - a[s] >= x)    ans++;
    28     for (int i=p+1; i<=n; ++i)
    29     {
    30         if (sum + a[i] <= r)    DFS (sum + a[i], cnt + 1, s, i);
    31     }
    32 }
    33 
    34 int main(void)        //Codeforces Round #306 (Div. 2) B. Preparing Olympiad
    35 {
    36     while (scanf ("%d%d%d%d", &n, &l, &r, &x) == 4)
    37     {
    38         ans = 0;
    39         for (int i=1; i<=n; ++i)    scanf ("%d", &a[i]);
    40         sort (a+1, a+1+n);
    41         for (int i=1; i<n; ++i)    DFS (a[i], 1, i, i);
    42         printf ("%d
    ", ans);
    43     }
    44 
    45     return 0;
    46 }
    47 
    48 /*
    49 3 5 6 1
    50 1 2 3
    51 4 40 50 10
    52 10 20 30 25
    53 5 25 35 10
    54 10 10 20 10 20
    55 */
    编译人生,运行世界!
  • 相关阅读:
    SpringBoot之使用外部的启动类
    CCF——最小差值(2017-12)
    CCF——买菜(2018-09)
    CCF——卖菜(2018-09)
    2792. Grammar Lessons
    2756. Lucky Transformation
    2776. String Task
    2794. Petya and Strings
    2810. Palindromic Times
    14. Football
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4555233.html
Copyright © 2011-2022 走看看