B - Preparing Olympiad
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 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
Input3 5 6 1
1 2 3Output2Input4 40 50 10
10 20 30 25Output2Input5 25 35 10
10 10 20 10 20Output6Hint
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.
搜索忘得真是彻底啊摔!
是时候系统的学习一下算法了。
最新文章
- WPF数据验证
- HDU1215(筛选法)
- How to apply Local Group Policy settings silently using the ImportRegPol.exe and Apply_LGPO_Delta.exe utilities.
- 对EJB返回的AaaryList显示到table的处理方法
- 零零碎碎写的shell脚本(三):一键自动归档压缩脚本
- cmd.exe-应用程序错误 应用程序无法正常启动(0xc0000142)
- android利用数字证书对程序签名
- php中fopen函数用法详解(打开文件)
- linux mail 配置
- Java语言程序设计(基础篇) 第八章 多维数组
- freemarker 中可以直接使用的内置对象
- 使用WireShark分析使用RedisTemplate取不到值的问题
- 【mysql】数据库Schema的优化
- mybatis的配置文件中<;selectKey>;标签问题
- 四、spring成长之路——springIOC容器(下)
- 【C++】new和delete表达式与内存管理
- [Todo] Redis里面队列的两种模式,以及抢红包在Redis中的实现
- Luogu 3616 富金森林公园
- 学习SQLite基本语句
- AngularJs学习笔记(1)——ng-app