CodeForces 550B Preparing Olympiad 简单DFS
来源:互联网 发布:厦门第二世界网络 编辑:程序博客网 时间:2024/06/06 04:57
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.
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.
Print the number of ways to choose a suitable problemset for the contest.
3 5 6 11 2 3
2
4 40 50 1010 20 30 25
2
5 25 35 1010 10 20 10 20
6
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.
个人感觉比较简单的一个DFS吧,就是为了方便我自己弄得参数比较多但是也比较好理解QAQ
#include <bits/stdc++.h>using namespace std;int n,l,r,x,c[20],ans,cur;void dfs(int p,int q,int m,int la,int ra,int sum){ if(p==m) { if(ra-la>=x&&sum<=r&&sum>=l) ans++; return; } for(int i=q+1;i<=n;i++) if(c[i]+sum<=r) dfs(p+1,i,m,min(la,c[i]),max(ra,c[i]),sum+c[i]); return ;}int main(){ while(cin>>n>>l>>r>>x) { ans=0; for(int i=1;i<=n;i++) cin>>c[i]; for(int i=2;i<=n;i++) { for(int j=1;j<=n;j++) dfs(1,j,i,c[j],c[j],c[j]); } cout<<ans<<endl; } return 0;}
- CodeForces 550B Preparing Olympiad 简单DFS
- codeforces 550B Preparing Olympiad(DFS+回溯)
- Codeforces Round 306 B Preparing Olympiad(简单dfs)
- CodeForces 550B Preparing Olympiad
- codeforces-550B-Preparing Olympiad
- codeforces 550B Preparing Olympiad
- Preparing Olympiad CodeForces - 550B
- 【codeforces 550B】Preparing Olympiad
- CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)
- CodeForces 550B Preparing Olympiad(dfs暴搜)
- codeforces 550B Preparing Olympiad(枚举)
- CodeForces 550B Preparing Olympiad 暴搜
- Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs
- codeforces #306 550B B. Preparing Olympiad(位压缩枚举)
- CodeForces 550B Preparing Olympiad(状态压缩,暴搜)
- codeforces 306 div.2 B. Preparing Olympiad
- dfs Preparing Olympiad
- B. Preparing Olympiad
- 母函数 入门 + 模板
- 轻松实现定时调度[Spring Task + Cron]
- select option
- 剑指offer-翻转单词顺序
- java Stack源代码实现
- CodeForces 550B Preparing Olympiad 简单DFS
- 2016-10-30
- 在Ubuntu下开发React-Native之填坑记(一)
- DrawerLayout must be measured with MeasureSpec.EXACTLY error
- CentOS7下编译安装ffmpeg3.1.5
- java线程等待/通知机制及中断
- poj 3984
- 关于"\r","\n","\r\n"区别的实践
- js 使元素获取或失去焦点