Preparing Olympiad

机械臂 关节电机选型计算 电机 机械臂 阅读详情

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 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 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
Note

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个题目,每个题目对应一个难度,试卷总难度要小于r,大于l,并且最简单的题目和最难的题目难度差要不小于x。

看到n的范围是15,很容易想到搜索。深搜可解,每个题目都有取和不取两个搜索状态,最后再看是否满足条件。注意:题目至少有两个,这个也要放在最终条件判断中。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n, l, r, x, ans, dp, pre, temp, leap[17], step;
int a[17];
bool cmp(int a, int b)
{
 return a < b;
}
void bfs(int p)
{
 int i, temp1, pre1;
 if (p == n + 1)
 {
  if (temp >= x&&dp >= l&&dp <= r&&step>=2)
   ans++;
 }
 else{
  
   if (!leap[p])
   {
    leap[p] = 1; step++;
    dp = dp + a[p];
    pre1 = pre;
    if (pre == 0){ pre = a[p]; }
    temp1 = temp; temp = a[p] - pre;
    bfs(p + 1);
    temp = temp1; pre = pre1; step--;
    dp = dp - a[p];
    bfs(p + 1);
    leap[p] = 0;
   }
  
 }
}
int main()
{
 int m, i, j;
 cin >> n >> l >> r >> x;
 for (i = 1; i <= n; i++)
  cin >> a[i];
 sort(a+1, a + n + 1, cmp);
 ans = 0; dp = 0; pre = 0; temp = 0; step = 0;
 memset(leap, 0, sizeof(leap));
 bfs(1);
 cout << ans << endl;
 return 0;
}

⑤单细胞学习-cellchat组间通讯差异分析 参考: 阅读详情

相关推荐

[前沿技术] AMD FSR 1.0源码解析:EASU算法实现细节与优化策略

本文深入解析了AMD FSR 1.0技术的核心——EASU(边缘自适应空间升频)算法。通过剖析其源码,详细阐述了EASU如何利用12-tap采样窗口、基于Lanczos滤波器的多项式近似以及自适应的边缘检测机制,在无需AI模型的情况下实现高质量图像放大。文章重点揭示了其极致的GPU优化策略,包括寄存器利用、采样优化和避免动态分支,为理解高性能图形算法提供了绝佳范例。

docker7nomad的博客 540

Preparing Olympiad CodeForces - 550B

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 t

w571523631的博客 475

SpringBoot+Vue前后端分离项目实战:个人博客系统

MyBlog主要是基于 SpringBoot + Vue 前后端分离开发的一款动态个人博客系统,后台和前台均通过JSON数据做交互,主要功能有文章管理、分类管理、标签管理、附件管理、评论管理、友链管理、个人资料/博客信息管理等。

Myles'Blog 1万+

Codeforces Round #306 (Div. 2)B. Preparing Olympiad--状态压缩

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 fo

qq_21820377的专栏 623

炼丹-Pyecharts: JupyterLab无法render_notebook

炼丹-Pyecharts: JupyterLab无法render_notebook问题描述Jupyter-Lab 环境下render_notebook显示空白 问题描述Jupyter-Lab 环境下render_notebook显示空白 首先需要使用pyecharts自带的config来申明一下使用pyecharts的运行环境 from pyecharts.globals import Curre...

MichaelZzzzz的博客 4687

拆解汽车T-Box:从4G模块到MCU,手把手教你理解车联网的‘黑匣子’

本文深入拆解汽车T-Box,揭示其作为车联网‘黑匣子’的核心架构与工作原理。从4G模块、MCU主控到外设接口,详细解析各组件功能及协同机制,并通过实战案例展示故障诊断与性能优化技巧,帮助读者全面理解T-Box在智能汽车中的关键作用。

weixin_30955617的博客 493

CodeForces - 550B Preparing Olympiad【状态压缩】

CodeForces - 550B 题意: 在n个数中选出至少两个数字,使得它们的和在L,R之间,并且最大的与最小的差值要不小于x。 题解: n最大为15,可以直接爆搜,试了一下用状压写。 #include<bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; inline int read() { int s = 0, w = 1; char ch = getchar(); while(...

lllllan 247

把核心变干净的代价与回报:为什么推动 Clean Core,几乎绕不开 SAP Integration Suite 与 API Management

Clean Core的核心价值在于构建可持续升级的ERP系统架构,其关键不在于减少代码或限制扩展,而是通过解耦和治理实现系统边界的清晰划分。这一理念将推动企业从传统的"私搭乱建"式集成向平台化工程转型,而SAP Integration Suite和API Management正是实现这一转型的核心组件。 Integration Suite作为集成中枢,通过统一平台、可复用内容库和事件驱动架构,将碎片化连接转变为标准化能力;API Management则负责建立接口治理体系,通过统一入口、

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 241

状态压缩

B - Preparing Olympiad  CodeForces - 550B  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...

ACM 628

图解联合概率密度、边缘概率密度、条件概率密度之间的关系

简要图解联合概率密度、边缘概率密度、条件概率密度之间的关系

一个搬运知识的笨小孩 2万+

SAP-MM:SAP MM(物料管理)模块 的系统化学习计划

SAP MM模块的系统化学习计划

baidu_35680696的博客 1547

dfs Preparing Olympiad

#include using namespace std; const int N=1e5+10; int num[N],mum[N]; int n,m,q,t,l,r; int top,ans,cnt; void dfs(int sum,int d,int x,int minn)///和,差值,当前循环,最小数 { if(sum>=l&&sum=q) ans++; if(sum

RockyHOO1209的博客 399

OpenClaw 2026 路线图详解:3 大协作能力升级与社区贡献增长 62% 的实证分析

介绍 OpenClaw 2026 如何通过上下文锚定(Context Anchoring)、协作质量定义和责任边界机制,将 AI 编程工具从单点补全升级为嵌入代码生命周期的协作对齐系统,并详解 `.openclaw/config.yaml` 中 `context_anchor` 配置的实操方法与效果

weixin_42545292的博客 383

A. Preparing for the Olympiad

解题说明:此题采用贪心算法,为了让差值最大,遍历两个数列,比对所有Ai和Bi+1的大小。如果A[i] > B[i+1] 那么将他们的差值累加,得到最大值。

无知的我 1020

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

codeforces-550B-Preparing Olympiad

550B-Preparing Olympiad

Linoy 1602

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

[codeforces] B. Preparing Olympiad

B. Preparing Olympiadtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have n problems. You have estimated the difficulty of the i-th one as int...

jing16337305的博客 292

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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

无知的我 1345

CodeForces 550B Preparing Olympiad

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 fo

qq_29055721的博客 441

B - Preparing Olympiad

Time Limit:2000MSMemory Limit:262144KB64bit IO Format:%I64d & %I64u Description You havenproblems. You have estimated the difficulty of thei-th one as integerci. Now you w...

weixin_30699235的博客 171

codeforces 550B Preparing Olympiad

刷题的路上 还差的很远呢。 一看就知道用DFS + 回溯 但就是想不出来 最后还是看了别人的代码才有思路的。 诶 忧郁。 不知道题目链接 是给新生做的训练里看到的(丢人!) #include #include #include using namespace std; int n, l, r, x; int num[15]; int temp[15

Arizona不放弃 444

Preparing Olympiad CodeForces #550B 题解[C++]

题目来源 http://codeforces.com/problemset/problem/550/B 题意理解 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...

Wayne_Mai的博客 554

【codeforces 550B】Preparing Olympiad

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You have n problems. You have estimated the difficulty of the i-th one as in...

82

Codeforces 550B Preparing Olympiad

B. Preparing Olympiad time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You have n problems. You have estimated the difficul...

hanyanwei123的博客 326

Codeforces550B:Preparing Olympiad

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 fo

ACM!荣耀之路! 1635
上一篇: Two Substrings
下一篇: Divisibility by Eight
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值