Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.

A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.

Find the number of ways to choose a problemset for the contest.

Input

The first line contains four integers nlrx (1 ≤ n ≤ 15, 1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ 106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.

The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 106) — the difficulty of each problem.

Output

Print the number of ways to choose a suitable problemset for the contest.

Sample Input

Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6

Hint

In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.

In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.

In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.

题意:

n个题目,最少取2个使得难度和在l和r之间且极值差不小于x

DFS跑一遍即可。

附AC代码:

 #include<iostream>
#include<cmath>
using namespace std; const int INF=<<;
int n,l,r,x;
int a[];
int ans=; void DFS(int num,int MAX,int MIN,int sum){
if(num==n+){
return;
}
if(sum<=r&&sum>=l&&x<=MAX-MIN&&num==n){
ans++;
}
DFS(num+,max(MAX,a[num]),min(MIN,a[num]),sum+a[num]);//取
DFS(num+,MAX,MIN,sum);//不取
} int main(){
cin>>n>>l>>r>>x;
for(int i=;i<n;i++){
cin>>a[i];
}
ans=;
DFS(,,INF,);
cout<<ans<<endl;
return ;
}

p.s.

搜索忘得真是彻底啊摔!

是时候系统的学习一下算法了。

B - Preparing Olympiad的更多相关文章

  1. codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)

    B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...

  2. Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs

    B. Preparing Olympiad Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550 ...

  3. CF Preparing Olympiad (DFS)

    Preparing Olympiad time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  5. CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)

    [题目链接]:click here~~ [题目大意] 一组题目的数目(n<=15),每一个题目有对应的难度,问你选择一定的题目(大于r个且小于l个)且选择后的题目里最小难度与最大难度差不小于x, ...

  6. Codeforces Round #306 (Div. 2), problem: (B) Preparing Olympiad【dfs或01枚举】

    题意: 给出n个数字,要求在这n个数中选出至少两个数字,使得它们的和在l,r之间,并且最大的与最小的差值要不小于x.n<=15 Problem - 550B - Codeforces 二进制 利 ...

  7. Codeforces Round #306 (Div. 2)

    A. Two Substrings You are given string s. Your task is to determine if the given string s contains t ...

  8. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  9. Codeforces Round #306 (Div. 2)A B C D 暴力 位/暴力 暴力 构造

    A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. ssh 卡主

    偶尔会遇到这样的现象 ssh 登录一台远程机器,显示下面的信息然后hang在那 Connecting to 192.168.137.102:22... Connection established. ...

  2. 最大熵推导LR

    http://www.win-vector.com/dfiles/LogisticRegressionMaxEnt.pdf https://www.zhihu.com/question/2409455 ...

  3. 在Nginx上部署ThinkPHP,解决Pathinfo问题

    在Nginx上部署ThinkPHP,解决Pathinfo问题 事实上.要解决nginx不支持pathinfo的问题.有两个解决思路,一是不使用pathinfo模式,二是改动nginx的配置文件,使它支 ...

  4. Camtasia Studio如何添加画中画

    将录像文件和其他视频文件拖放到剪辑箱,右击录像文件(camrec文件)添加到时间轴,一般这个就是主要的视频文件,我们会在这个基础上添加字幕,配音,画中画等,拖进去之后可以发现多出来了一个视频1和音频1 ...

  5. v-if v-else-if v-else

    1.代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...

  6. GCD编程(封装GCD)

    //GCDGroup 类 @interface GCDGroup : NSObject @property (strong, nonatomic, readonly) dispatch_group_t ...

  7. oracle SQL语句(转)

    Oracle数据库语句大全 ORACLE支持五种类型的完整性约束 NOT NULL (非空)--防止NULL值进入指定的列,在单列基础上定义,默认情况下,ORACLE允许在任何列中有NULL值. CH ...

  8. 理解CSS中的BFC(块级可视化上下文)[译]

    开篇 一些元素,如float元素,如position为absolute,inline-block,table-cell或table-caption的元素,以及overflow属性不为visible的元 ...

  9. sed 修连接文件,有坑

    -bash-4.1# ll /etc/rc.local  lrwxrwxrwx. 1 root root 13 Aug 15  2014 /etc/rc.local -> rc.d/rc.loc ...

  10. SQL 通配符及其使用

    Sql Server中通配符的使用 通配符_ "_"号表示任意单个字符,该符号只能匹配一个字符."_"可以放在查询条件的任意位置,且只能代表一个字符.一个汉字只 ...