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. 修改Android 程序的icon快捷方式图标和名称

    在res/drawable-hdpi或res/drawable-ldpi或res/drawable-mdpi目录下,加下你要显示的图片,最好后缀是为.png的,然后修改AndroidManifest. ...

  2. VS2010开发环境最佳字体及配色[转]

    从地址:http://www.dev-club.net/xiangxixinxi/42010072906150537/201103010518006.html 获取的,整理如下: 环境:VS2010字 ...

  3. (剑指Offer)面试题26:复杂链表的复制

    题目: 请实现函数ComplexListNode* Clone(ComplexListNode* pHead),复制一个复杂链表. 在复杂链表中,每个结点除了有一个pNext指针指向下一个结点之外,还 ...

  4. OpenCV中图像指针注意点

    1.cvQueryFrame方法从摄像头或文件中抓取的帧图像是不能被释放和修改的 2.不要用delete删除,一定要用cvReleaseImage删除且要带有&符号.

  5. Codeforces Round #310 (Div. 1) C. Case of Chocolate set

    C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...

  6. Delphi和JAVA用UTF-8编码进行Socket通信例子

    最近的项目(Delphi开发),需要经常和java语言开发的系统进行数据交互(Socket通信方式),数据编码约定采用UTF-8编码. 令我无语的是:JAVA系统那边反映说,Delphi发的数据他们收 ...

  7. ios实例开发精品源码文章推荐

    iOS源码:游戏引擎-推箱子游戏 http://www.apkbus.com/android-106392-1-11.html iOS源码:进度条-Colorful ProgressView http ...

  8. LinQ—Lambda表达式

    概述 本篇博客主要解说lambda表达式,在这里将它的来龙去脉,主要是从托付,匿名函数这些方面过度讲的,当然,在讲托付和匿名函数的时候,主要是从Lambda的角度出发讲的,可能它们还具有其他的一些作用 ...

  9. C++ 二叉树遍历实现

    原文:http://blog.csdn.net/nuaazdh/article/details/7032226 //二叉树遍历 //作者:nuaazdh //时间:2011年12月1日 #includ ...

  10. Spring RESTFul Client – RestTemplate Example--转载

    原文地址:http://howtodoinjava.com/2015/02/20/spring-restful-client-resttemplate-example/ After learning ...