B. Preparing Olympiad

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/550/problem/B

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 n, l, r, x (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

3 5 6 1
1 2 3

Sample Output

2

HINT

题意

有n门课,然后让你选择一些课,要求这些课程的和小于等于r,大于等于l,最大值减去最小值至少为x

然后问你有多少种分法

题解:

数据范围小的可怜= =

所以直接dfs吧~

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll a[maxn];
int d[];
int ans=;
int n,l,r,x;
map<string,int> H;
void dfs(int t,int k[],ll sum,ll mi,ll ma)
{
if(sum>r)
return;
if(ma-mi>=x&&sum<=r&&sum>=l)
{
ans++;
}
for(int i=t;i<n;i++)
{
if(k[i]==)
{
k[i]=;
dfs(i,k,sum+a[i],min(mi,a[i]),max(ma,a[i]));
k[i]=;
}
}
return;
}
int main()
{
//test;
n=read(),l=read(),r=read(),x=read();
for(int i=;i<n;i++)
a[i]=read();
for(int i=;i<n;i++)
{
d[i]=;
dfs(i,d,a[i],a[i],a[i]);
d[i]=;
}
cout<<ans<<endl;
}

Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs的更多相关文章

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

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

  2. 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

    题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...

  3. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

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

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

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

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

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

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

  8. Codeforces Round #222 (Div. 1) B. Preparing for the Contest 二分+线段树

    B. Preparing for the Contest 题目连接: http://codeforces.com/contest/377/problem/B Description Soon ther ...

  9. Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造

    E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

随机推荐

  1. [算法 笔记]2014年去哪儿网 开发笔试(续)第一题BUG修正

    上一篇的blog地址为:http://www.cnblogs.com/life91/p/3313868.html 这几天又参加了一个家公司的笔试题,在最后的编程题中竟然出现了去哪儿网开发的第一题,也就 ...

  2. openGl从零开始之添加颜色

    OpenGL 支持两种颜色模式:一种是 RGBA模式,一种是 颜色索引模式.无论哪种颜色模式,计算机都必须为每一个像素保存一些数据,即通过每一个像素的颜色,来改变整体图形的颜色.不同的是, RGBA ...

  3. C# 类和结构

    类和结构实际上都是创建对象的模板,每个对象都包含数据,并提供了处理和访问数据的方法 . 类定义了类的每个对象(称为实例)可以包含什么数据和功能. 例如,如 果一个类表示一个顾客,就可以定义字段 Cus ...

  4. (转载)OC学习篇之---类目的概念和使用

    上一篇文章介绍了OC中的@class关键字的使用,这一篇我们介绍一下,OC中的一个特有的亮点:类目 首先我们来看一下场景,如果我们现在想对一个类进行功能的扩充,我们该怎么做? 对于面向对象编程的话,首 ...

  5. Numpy中的矩阵合并

    列合并/扩展:np.column_stack() 行合并/扩展:np.row_stack() >>> import numpy as np >>> a = np.a ...

  6. BOX2D测试

    ; ; Box2DTestLayer = cc.Layer.extend({ world:null, //GLESDebugDraw *m_debugDraw; ctor:function () { ...

  7. github上所有项目的受欢迎程度排名,包括超大型项目

    直接打开如下网址: https://github.com/search?l=Java&q=+stars%3A%3E0&ref=searchresults&type=Reposi ...

  8. Using Boost Libraries in Windows Store and Phone Applications

    Using Boost Libraries in Windows Store and Phone Applications RATE THIS Steven Gates 18 Jul 2014 5:3 ...

  9. 【转】eclipse.ini内存设置

    -vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:MaxPermSize=128M 这里有几个问题:1. 各个参数的含义什么?2. 为什么有的机器我将-Xm ...

  10. binarySearch二分查找——Javascript实现

    在很早之前,我就写过了一篇也关于二分法的相关博文:JavaScript快排与原生sort的测试.当时是用二分法进行快速排序,其实和这次思路大致相当.二分查找最重要的一个条件,就是需要将数组先按照从小到 ...