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.

搜索忘得真是彻底啊摔!

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

最新文章

  1. WPF数据验证
  2. HDU1215(筛选法)
  3. How to apply Local Group Policy settings silently using the ImportRegPol.exe and Apply_LGPO_Delta.exe utilities.
  4. 对EJB返回的AaaryList显示到table的处理方法
  5. 零零碎碎写的shell脚本(三):一键自动归档压缩脚本
  6. cmd.exe-应用程序错误 应用程序无法正常启动(0xc0000142)
  7. android利用数字证书对程序签名
  8. php中fopen函数用法详解(打开文件)
  9. linux mail 配置
  10. Java语言程序设计(基础篇) 第八章 多维数组
  11. freemarker 中可以直接使用的内置对象
  12. 使用WireShark分析使用RedisTemplate取不到值的问题
  13. 【mysql】数据库Schema的优化
  14. mybatis的配置文件中&lt;selectKey&gt;标签问题
  15. 四、spring成长之路——springIOC容器(下)
  16. 【C++】new和delete表达式与内存管理
  17. [Todo] Redis里面队列的两种模式,以及抢红包在Redis中的实现
  18. Luogu 3616 富金森林公园
  19. 学习SQLite基本语句
  20. AngularJs学习笔记(1)——ng-app

热门文章

  1. 论DATASNAP结合FIREDAC的使用方法
  2. 超级强大的淘宝开源平台(taobao-code)
  3. AppCompatActivity
  4. BUPT复试专题—统计字母(2008)
  5. HTML5面试题-b
  6. plsql 无需配置客户端连接.
  7. Linux启动过程笔记
  8. Nova虚拟机启动提示libvirtError
  9. 深入理解Atomic原子操作和volatile非原子性
  10. 安装sbt