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. 【java】java 中 byte[]、File、InputStream 互相转换

    ========================================================================= 使用过程中,一定要注意close()掉各个读写流!! ...

  2. PPT中的图像失真

    现象:Office PowerPoint 保存出来的PPT文件在WPS下播放的时候会出现图像失真的显现. 解决方法:Office PowerPoint打开PPT将里面的图像另存为BMP格式的图像文件, ...

  3. Linux之时钟中断

    from:深入分析Linux内核源码(http://oss.org.cn/kernel-book/) 时钟中断的产生 Linux的OS时钟的物理产生原因是可编程定时/计数器产生的输出脉冲,这个脉冲送入 ...

  4. react map 遍历

    1.map方法 注:map 返回的是一个新数组 class App extends Component { // constructor(props) { // super(props); // th ...

  5. PHP读取excel(4)

    这一小节内容主要是PHPExcel读取少量excel数据,具体代码如下: <?php //数据较少的时候,一次性读取出来放到数组里 header("Content-Type:text/ ...

  6. Android 关于BottomDialogSheet 与Layout擦出爱的火花?

    今天上班做那个相似于ios拍照的那种效果图 就是个垂直布局然后里面textview+切割线+textview+button 当然也能够用button+切割线+button 方法有非常多,选择适合自己的 ...

  7. Android的onMeasure方法

    在Android开发中,当Android原生控件不能满足我们的需求的时候,就需要自定义View.View在屏幕上绘制出来先要经过measure(计算)和layout(布局). 什么时候调用onMeas ...

  8. 宠物连连看2完整Android代码项目

    宠物连连看2完整代码,该源代码支持多种风格的连连看游戏的,如有国旗类的连连看,还有宠物连连看的等,主要的功能实现了无尽关卡挑战模式.还有催命倒计时,以及链接提示,暂停.多样图片集,挑战眼力和速度等,而 ...

  9. XJTUOJ wmq的A×B Problem FFT/NTT

    wmq的A×B Problem 发布时间: 2017年4月9日 17:06   最后更新: 2017年4月9日 17:07   时间限制: 3000ms   内存限制: 512M 描述 这是一个非常简 ...

  10. Record is locked by another user

    Oracle修改表中记录时出现record is locked by another user的问题 在操作表时没有commit,导致表被锁,只要执行下面两行语句,就可以了将行锁解锁了. Select ...