CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)
【题目链接】:click here~~
【题目大意】
一组题目的数目(n<=15),每一个题目有对应的难度,问你选择一定的题目(大于r个且小于l个)且选择后的题目里最小难度与最大难度差不小于x,求选择方案数。
【解题思路】:
DFS+回溯。
先发一发比較拙的代码:
#include <bits/stdc++.h>
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<=r&&d>=q) ans++;
if(sum>r) return;
///if(sum<l) return;当前累加的sum可能小于l
for(int i=x;i<=n;++i)
{
dfs(sum+num[i],num[i]-minn,i+1,minn);
}
}
int main()
{
while(cin>>n>>l>>r>>q)
{
ans=0;
memset(num,0,sizeof(num));
for(int i=1; i<=n; ++i) scanf("%d",&num[i]);
sort(num+1,num+1+n);
for(int i=1; i<=n; ++i)
{
dfs(num[i],0,i+1,num[i]);///为了參照最大和最小,引入最小数
}
printf("%d\n",ans);
}
return 0;
}CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)的更多相关文章
- codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)
B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...
- 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 ...
- CF Preparing Olympiad (DFS)
Preparing Olympiad time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)
Generalized Palindromic Number Time Limit: 2 Seconds Memory Limit: 65536 KB A number that will ...
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- Codeforces Round #253 (Div. 2)B(暴力枚举)
就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include< ...
- HDU 4431 Mahjong (DFS,暴力枚举,剪枝)
题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...
- codeforces 869A The Artful Expedient【暴力枚举/亦或性质】
A. time limit per test 1 second memory limit per test 256 megabytes input standard input output stan ...
- Codeforces 791A Bear and Big Brother(暴力枚举,模拟)
A. Bear and Big Brother time limit per test:1 second memory limit per test:256 megabytes input:stand ...
随机推荐
- Vue经典开源项目
Vue常用的开源项目和插件库 UI组件 element ★34,784 - 饿了么出品的基于Vue2的web UI工具套件storybook ★33,503 - 响应式UI 开发及测试环境Vux ★1 ...
- 主流框架(SSH及SSM)配置文件的模板头文件
SSH三大框架整合配置头文件模板如下: 一:Spring配置文件(beans.xml)模板:<beans xmlns="http://www.springframework.or ...
- xcode5.1生成framework,支持arm64报错
错误例如以下: ld: Assertion failed: (_machoSection != 0), function machoSection, file /SourceCache/ld64/ld ...
- iOS给label加入下划线
UILabel *myLabel = [[UILabelalloc] ,, , )]; NSMutableAttributedString *content = [[NSMutableAttribut ...
- jQuery——map()函数以及它的java实现
map()函数小简单介绍 map()函数一直都是我觉得比較有用的函数之中的一个,为什么这么说呢? 先来考虑一下.你是否碰到过下面场景:须要遍历一组对象取出每一个对象的某个属性(比方id)而且用分隔符隔 ...
- linux下开发,解决cocos2d-x中编译出现的一个小问题, undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
解决cocos2d-x中编译出现的一个小问题 对于cocos2d-x 2.×中编译中,若头文件里引入了#include "cocos-ext.h",在进行C++编译的时候会遇到例如 ...
- Centos yum 安装lamp PHP5.4版本号
centos 6.5 1.yum安装和源码编译在使用的时候没啥差别.可是安装的过程就大相径庭了,yum仅仅须要3个命令就能够完毕,源码须要13个包,还得加压编译.步骤非常麻烦,并且当做有时候会出错,源 ...
- 【源代码】将一个整数的每位数分解并按逆序放入一个数组中(用递归算法)(C语言实现)
帮朋友做的,好像是一个面试题.假设不过考察递归的话.应该是够了,程序的健壮性和通用性都非常一般的说-- #include <stdio.h> #include <stdlib.h&g ...
- m_Orchestrate learning system---十八、mo项目的启示是什么
m_Orchestrate learning system---十八.mo项目的启示是什么 一.总结 一句话总结:多看教程,体统看教程的学, 完全不懂的话百度的作用也不大 多学点,可以节约后面的超多时 ...
- elasticsearch index 之 put mapping
elasticsearch index 之 put mapping mapping机制使得elasticsearch索引数据变的更加灵活,近乎于no schema.mapping可以在建立索引时设 ...