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/problem/B
Description
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 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的更多相关文章
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- 水题 Codeforces Round #306 (Div. 2) A. Two Substrings
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...
- 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. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
- 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 ...
- Codeforces Round #306 (Div. 2), problem: (B) Preparing Olympiad【dfs或01枚举】
题意: 给出n个数字,要求在这n个数中选出至少两个数字,使得它们的和在l,r之间,并且最大的与最小的差值要不小于x.n<=15 Problem - 550B - Codeforces 二进制 利 ...
- 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 ...
- 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 ...
随机推荐
- VC远控(二)连接Server端及密码验证
首先服务端是一个win32console应用程序. 在建立项目的时候需要勾选MFC 套接字的初始化同客户端相似: //对套接字进行初始化 WSADATA wsadata; WORD ver = MAK ...
- mssql 容易掉进的坑
1. 重复 使用 into #tabel(不是在开头使用insert into ) 会报错 if 1=1 begin select * into #tabel from product ...
- 使用HttpClient实现文件的上传下载
1 HTTP HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源. 虽然在 JDK 的 java.net ...
- RVM 安装&下载Ruby
1. #查看当前ruby版本 2. $ ruby -v 3. ruby 1.8.7 4. #列出已知的ruby版本 5. $ rvm list known 6. #安装ruby 1.9.3 7. $ ...
- oracle 去掉空格
trim(value) 去掉左右空格 ltrim(value) 去掉左空格 rtrim(value) 去掉右空格
- C#实现office文档转换为PDF或xps的一些方法( 转)
源博客http://blog.csdn.net/kable999/article/details/4786654 代码支持任意office格式 需要安装office 2007 还有一个office20 ...
- Advanced Scene Processing
[How a Scene Processes Frames of Animation] In the traditional view system, the contents of a view a ...
- OperateParticleWithCodes
[OperateParticleWithCodes] Listing 6-6 shows how you might configure an emitter’s scale property. Th ...
- python知识点(07-08)
python: 循环else: while true: if x>1: print() break else: print() 文件循环: for line in open(‘test.txt’ ...
- windows 7 获取SYSTEM权限
当Adobe Reader 9.0卸载之后,你会发现原来的C:\Program Files\Adobe\Reader 9.0\Resource\CMap文件夹下的一些文件无法删除,提示你需要SYSTE ...