CF Preparing Olympiad (DFS)
2 seconds
256 megabytes
standard input
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.
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.
Print the number of ways to choose a suitable problemset for the contest.
3 5 6 1
1 2 3
2
4 40 50 10
10 20 30 25
2
5 25 35 10
10 10 20 10 20
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)的更多相关文章
- 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 ...
- CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)
[题目链接]:click here~~ [题目大意] 一组题目的数目(n<=15),每一个题目有对应的难度,问你选择一定的题目(大于r个且小于l个)且选择后的题目里最小难度与最大难度差不小于x, ...
- codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)
B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
- Codeforces Round #306 (Div. 2), problem: (B) Preparing Olympiad【dfs或01枚举】
题意: 给出n个数字,要求在这n个数中选出至少两个数字,使得它们的和在l,r之间,并且最大的与最小的差值要不小于x.n<=15 Problem - 550B - Codeforces 二进制 利 ...
- cf Permute Digits(dfs)
C. Permute Digits You are given two positive integer numbers a and b. Permute (change order) of the ...
- B - Preparing Olympiad
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description You ha ...
- 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 ...
- Codeforces Round #306 (Div. 2) ABCDE(构造)
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
随机推荐
- Unity3d:加载Format是RGB24位的图片失败(加载图片显示问号)
问题描述:加载图片显示是个红色的问号,调试发现,Texture的Format=RGB24的都加载失败,ARGB32位的都能成功,按照常规,首先去度娘,看是否有人遇到和我同样的问题,结果一无所获.将用N ...
- com.sun.image.codec.jpeg--导入报错
import com.sun.image.codec.jpeg; 这样导入的时候,总是报错:Only a type can be imported. com.sun.image.codec.jpeg ...
- 关于Java中的程序,进程和线程的详解...
程序:一段静态的代码,一组指令的有序集合,它本身没有任何运行的含义,它只是一个静态的实体,是应用软件执行的蓝本. 进程:是程序的一次动态执行,它对应着从代码加载,执行至执行完毕的一个完整的过程,是一个 ...
- 【M35】让自己习惯于标准C++语言
1.最近一些年C++语言增加的特性有: a.RTTI,namespace,bool,关键字mutable和explicit,enums,以及const static int可以直接初始化. b.扩充了 ...
- UVA 12897 Decoding Baby Boos 暴力
Decoding Baby Boos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contes ...
- java建立二叉树,递归/非递归先序遍历,递归/非递归中序遍历,层次遍历
import java.util.LinkedList; import java.util.Scanner; import java.util.Stack; //structure of binary ...
- 即时通信(RPC)的Rtmp实现--配置篇
http://flexman.blog.sohu.com/129838570.html http://flexman.blog.sohu.com/130007574.html step 1: 首先要确 ...
- 摘录知乎上关于android开发的话题精华
1.初学者学习 Android 开发,有什么好网站推荐? http://www.zhihu.com/question/19611325 2.Android 开发有哪些新技术出现? http://www ...
- python类型转换、数值操作(转)
最近学习python语言,碰到数据类型间的转换问题.看到一篇文章总结的挺详细,收藏之备用. 类型转换 代码 Code highlighting produced by Actipro CodeHigh ...
- libgo协程库:网络性能完爆ASIO异步模型(-O3测试)
在purecpp社区的github组织中有一个协程库:https://github.com/yyzybb537/libgo 近日有用户找到我,想要了解一下libgo库在网络方面的性能,于是选取已入选标 ...