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 ...
随机推荐
- 6、Android中的NFC技术
Android对NFC技术的支持 Android2.3.1(API Level = 9)开始支持NFC技术,但Android2.x和Android3.x对NFC的支持非常有限.而从Android4.0 ...
- 【LeetCode 239】Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...
- 建立连接ALM的xml config文件
我就不贴所有的了,如果有谁想要所有源码和应用程序,可以密我 这里我贴下如何在第一次运行的时候自动建立一个ALMConfig的xml文件 private static void CreateALMCon ...
- leetcode:Integer to Roman(整数转化为罗马数字)
Question: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the rang ...
- C#语言基础01
Console.WriteLine("hello"); Console.ReadKey();// 按一个按键继续执行 string s=Console.ReadLine();//用 ...
- Windows Azure Platform 系列文章目录
Windows Azure Platform (一) 云计算的出现 Windows Azure Platform (二) 云计算的分类和服务层次 Windows Azure Platform (三) ...
- Xcode集成Google Test
Xcode集成Google Test 1.下载源代码https://github.com/google/googletest 2.进入下载文件目录下googletest/make中运行make gte ...
- cocos2d-x中有一个JniHelper类详细使用
主体思路 通过JNI获取java虚拟机,再获取当前程序的JNI环境,通过JNI环境获取需要调用的java类信息,再获取需要调用的java类中的函数信息.再通过JNI环境调用,使用类信息.函数信息,调用 ...
- [翻译]Behavior-Driven Development (BDD)行为驱动开发(二)
测试驱动开发体现了开发人员对软件产品各部分运作方式的理解,而行为驱动开发则关注于开发人员对软件产品最终表现的行为的预期. 行为驱动开发 TDD更像是一种范式而不是一个过程.它描述了一种先编写测试,然后 ...
- NSLog中的%@
[NSLog中的%@] There is one additional substitution token available in Objective-C, %@, used to denote ...