CUC-SUMMER-2-F(二進(jìn)制)

F - Preparing Olympiad
CodeForces - 550B

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.

Example
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
Note
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.


題意:每一道題都有一個難度系數(shù)低千,做一個題集使題的難度之和在給定范圍內(nèi),并且最難的和最容易的題的難度之差要大于給定值,求一共有多少種選題方式申窘。

解法:已知給定的題目數(shù)量最大值為15很小颁股,用枚舉法肝谭,對于一道題只有選和不選兩種情況谴返,用二進(jìn)制法存儲選擇情況结榄。

代碼:

#include<iostream>
using namespace std;
int a[15];
int main()
{
    int n,l,r,s;
    int ans=0;
    cin>>n>>l>>r>>s;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=1;i<=(1<<n)-1;i++){
        int sum=0,num=0;
        int minn=9999999,maxn=0;
        for(int j=0;j<n;j++)
            if((1<<j)&i){
                num++;
                sum+=a[j];
                maxn=max(maxn,a[j]);
                minn=min(minn,a[j]);
            }
        if(sum<=r&&sum>=l&&maxn-minn>=s&&num>1)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末墩蔓,一起剝皮案震驚了整個濱河市梢莽,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌奸披,老刑警劉巖昏名,帶你破解...
    沈念sama閱讀 216,744評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異源内,居然都是意外死亡葡粒,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,505評論 3 392
  • 文/潘曉璐 我一進(jìn)店門膜钓,熙熙樓的掌柜王于貴愁眉苦臉地迎上來嗽交,“玉大人,你說我怎么就攤上這事颂斜》虮冢” “怎么了?”我有些...
    開封第一講書人閱讀 163,105評論 0 353
  • 文/不壞的土叔 我叫張陵沃疮,是天一觀的道長盒让。 經(jīng)常有香客問我,道長司蔬,這世上最難降的妖魔是什么邑茄? 我笑而不...
    開封第一講書人閱讀 58,242評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮俊啼,結(jié)果婚禮上肺缕,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好同木,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,269評論 6 389
  • 文/花漫 我一把揭開白布浮梢。 她就那樣靜靜地躺著,像睡著了一般彤路。 火紅的嫁衣襯著肌膚如雪秕硝。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,215評論 1 299
  • 那天洲尊,我揣著相機(jī)與錄音远豺,去河邊找鬼。 笑死颊郎,一個胖子當(dāng)著我的面吹牛憋飞,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播姆吭,決...
    沈念sama閱讀 40,096評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼榛做,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了内狸?” 一聲冷哼從身側(cè)響起检眯,我...
    開封第一講書人閱讀 38,939評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎昆淡,沒想到半個月后锰瘸,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,354評論 1 311
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡昂灵,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,573評論 2 333
  • 正文 我和宋清朗相戀三年避凝,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片眨补。...
    茶點(diǎn)故事閱讀 39,745評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡管削,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出撑螺,到底是詐尸還是另有隱情含思,我是刑警寧澤,帶...
    沈念sama閱讀 35,448評論 5 344
  • 正文 年R本政府宣布甘晤,位于F島的核電站含潘,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏线婚。R本人自食惡果不足惜遏弱,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,048評論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望塞弊。 院中可真熱鬧腾窝,春花似錦缀踪、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,683評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽奏候。三九已至循集,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間蔗草,已是汗流浹背咒彤。 一陣腳步聲響...
    開封第一講書人閱讀 32,838評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留咒精,地道東北人镶柱。 一個月前我還...
    沈念sama閱讀 47,776評論 2 369
  • 正文 我出身青樓,卻偏偏與公主長得像模叙,于是被迫代替她去往敵國和親歇拆。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,652評論 2 354

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,479評論 0 23
  • 閑聽落雨倦梳妝范咨, 懶倚花窗黯自傷故觅。 古硯蒙塵無意顧, 名琴不撫任其荒渠啊。
    枼曦閱讀 102評論 0 1
  • 最近输吏,總有一個畫面浮現(xiàn)在腦海,讓我突然想把它描繪出來替蛉。那是多年前的一個夜晚贯溅,我們剛剛上高一,新組建的班級同學(xué)在正月...
    也許這是另一個我閱讀 200評論 0 0
  • 從初學(xué)OC的時候就聽人提起過OC對象中的isa指針躲查,用來指向?qū)ο笏鶎俚念愃常瑥亩梢栽谡{(diào)用方法時通過isa指針找到相...
    VoyageCN閱讀 4,127評論 5 4