Preparing Olympiad
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
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

#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <climits>
using namespace std; int N,L,R,X;
int ANS,SUM,DIF,NUM,MAX,MIN = 0x7fffffff;
int S[];
bool VIS[]; void dfs(int);
int main(void)
{
cin >> N >> L >> R >> X;
for(int i = ;i < N;i ++)
cin >> S[i];
sort(S,S + N);
dfs();
cout << ANS << endl; return ;
} void dfs(int start)
{
for(int i = start;i < N;i ++)
if(!VIS[i])
{
int back = DIF;
int back_min = MIN;
int back_max = MAX;
MIN = MIN < S[i] ? MIN : S[i];
MAX = MAX > S[i] ? MAX : S[i];
VIS[i] = true;
SUM += S[i];
DIF = MAX - MIN;
NUM += ;
if(SUM >= L && SUM <= R && NUM >= && DIF >= X)
ANS ++;
if(SUM <= R)
dfs(i);
VIS[i] = false;
SUM -= S[i];
DIF = back;
NUM -= ;
MIN = back_min;
MAX = back_max;
DIF = MAX - MIN;
}
}

CF Preparing Olympiad (DFS)的更多相关文章

  1. 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 ...

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

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

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

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

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

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

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

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

  6. cf Permute Digits(dfs)

    C. Permute Digits You are given two positive integer numbers a and b. Permute (change order) of the ...

  7. B - Preparing Olympiad

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

  8. 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 ...

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

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

随机推荐

  1. branch

    1.删除分支 git branch -d branch_name error: The branch 'branch_name' is not fully merged. If you are sur ...

  2. Hello OSGI --- Apache Felix

    Apache Felix Felix是一个OSGi版本4规范的Apache实现. OSGi是一个基于Java的服务平台规范,其目标是被需要长时间运行.动态更新.对运行环境破坏最小化的系统所使用.有许多 ...

  3. 【官方文档】Hadoop分布式文件系统:架构和设计

    http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_design.html 引言 前提和设计目标 硬件错误 流式数据访问 大规模数据集 简单的一致性模型 “移动计 ...

  4. Hadoop on Mac with IntelliJ IDEA - 5 解决java heap space问题

    本文讲述在CentOS 6.5中提交作业到hadoop 1.2.1于reduce阶段遇到Error: java heap space错误导致作业重新计算的解决过程.解决办法适用Linux.Mac OS ...

  5. [转]iOS应用性能调优的25个建议和技巧

    写在前面 本文来自iOS Tutorial Team 的 Marcelo Fabri,他是Movile的一名 iOS 程序员.这是他的个人网站:http://www.marcelofabri.com/ ...

  6. 编写你自己的单点登录(SSO)服务

    王昱 yuwang881@gmail.com   博客地址http://yuwang881.blog.sohu.com 摘要:单点登录(SSO)的技术被越来越广泛地运用到各个领域的软件系统其中.本文从 ...

  7. 博客标题栏增加一个"闪存“按钮

    最近来博客园喜欢去闪存上看看,也就是一个类似微博的东西,但是貌似没看到哪里有这个按钮. 所以只要自己动手搞一个. 暴力猴js: // ==UserScript== // @name fwindpeak ...

  8. ajax跳转页面问题

    $.ajax({ type:"POST", url: //你的请求程序页面随便啦 async:false,//同步:意思是当有返回值以后才会进行后面的js程序. data://请求 ...

  9. Kubuntu(14.04)共享wifi(热点)

    笔记本(kubuntu14.04)通过有线上网,共享本机无线给手机.平板及其他通过wifi上网的设备. 曾经在网上找过各种方法.下载了非常多软件都不能在本机上实现wifi共享,以下这样的方法眼下相对简 ...

  10. 【JavsScript】Ember.js

    现在,我们经常都可以看到复杂的JavaScript应用程序,由于这些应用程序变得越来越复杂,一长串的jQuery回调语句或者通过应用程序在各个状态执行不同的函数调用,这些做法都会变得无法再让人接受,这 ...