CodeForces 550B Preparing Olympiad 暴搜
来源:互联网 发布:心理学书籍推荐 知乎 编辑:程序博客网 时间:2024/05/29 04:40
题意:
给出N个题目的难度:请你出题满足下列要求
1.题目的数量不得少于两道
2.题目的难度不少于L,不超过R
3.最难的题和最简单的题的难度差不小于K
思路:
显然本题的每种状态都是要考录到的所以要暴力。递推不好写,可以用搜索。BFS也行,DFS也行。下面给出BFS的代码
BFS(1900ms)
#include <bits/stdc++.h>using namespace std;set <int> temp;int l,r,di;int a[20];int n;int ans;map <set<int>,bool>vis;const int INF=0x3f3f3f3f;typedef struct Node{ int maxn;int minn;set <int> vis;int sum; Node(int aa=0,int ii=0,set <int> vv=temp,int ss=0){ maxn=aa; minn=ii; vis=vv; sum=ss; }}Node;void bfs(){ vis.clear(); temp.clear(); queue <Node> que; Node st(0,INF,temp,0); que.push(st); while(!que.empty()){ Node t=que.front(); if(t.vis.size()>=2&&t.maxn-t.minn>=di&&t.sum<=r&&t.sum>=l){ //cout<<t.maxn<<' '<<t.minn<<' '<<t.sum<<endl; ans++; } que.pop(); for(int i=0;i<n;i++){ Node ne; ne.maxn=max(a[i],t.maxn); ne.minn=min(a[i],t.minn); ne.vis=t.vis;ne.vis.insert(i); ne.sum=t.sum+a[i]; if(vis[ne.vis]==0){ que.push(ne); vis[ne.vis]=1; } } }}int main(){ while(cin>>n>>l>>r>>di){ for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); ans=0; bfs(); cout<<ans<<endl; }}
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
3 5 6 11 2 3
2
4 40 50 1010 20 30 25
2
5 25 35 1010 10 20 10 20
6
Hint
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.
- CodeForces 550B Preparing Olympiad 暴搜
- CodeForces 550B Preparing Olympiad
- codeforces-550B-Preparing Olympiad
- codeforces 550B Preparing Olympiad
- Preparing Olympiad CodeForces - 550B
- 【codeforces 550B】Preparing Olympiad
- CodeForces 550B Preparing Olympiad(状态压缩,暴搜)
- CodeForces 550B Preparing Olympiad(dfs暴搜)
- codeforces 550B Preparing Olympiad(DFS+回溯)
- codeforces 550B Preparing Olympiad(枚举)
- CodeForces 550B Preparing Olympiad 简单DFS
- codeforces #306 550B B. Preparing Olympiad(位压缩枚举)
- CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)
- codeforces 306 div.2 B. Preparing Olympiad
- B. Preparing Olympiad
- Codeforces Round 306 B Preparing Olympiad(简单dfs)
- Codeforces Round #306 (Div. 2) B. Preparing Olympiad
- Codeforces Round #306 (Div. 2)B. Preparing Olympiad--状态压缩
- Google浏览器(Chrome)快捷键大全
- CPU私有变量(per-CPU变量)
- 编写app的一些心得
- 开源连接池C3P0解析
- saturate_cast<uchar>( (g_nContrastValue*0.01)*( g_srcImage.at<Vec3b>(y,x)[c] ) + g_nBrightValue );
- CodeForces 550B Preparing Olympiad 暴搜
- poj-3723-生成树
- 基于主键映射的 一对一关系
- 不懂编程金融狗的葵花宝典03(python/K近邻法下篇/机器学习入门简单详细代码)
- ios sqlite 数据库文件的位置
- IO流之DataInputStream 、DataOutputStream
- 14.Java本地线程(ThreadLocal)
- OpenCV中Mat、cvMat和IplImage类型转换
- Centos7安装配置NFS服务和挂载