SRM 595 1A 2013.12.9

SRM 595 1A 2013.12.9

DIV 1

250

 

Problem Statement

    

Little Elephant from the Zoo of Lviv hassome balls arranged in a row. Each ball can be painted in one of two possiblecolors: black or white. Initially all the balls are painted white.

 

You are given an int M, which representsthe number of balls in the row. The balls are numbered from left to right,starting from 1. You are also given two vector <int>s L and R. To repaintballs, Little Elephant wants to use a robot. The robot will paint the balls inseveral consecutive stages. For each i, the i-th stage (1-based index) willlook as follows: First, the robot will choose one of the two colors: white orblack. Then, the robot will paint the balls with indices from L[i-1] to R[i-1],inclusive, using the chosen color. (Painting a ball covers all previous layersof paint.)

 

Return the number of different coloringsLittle Elephant can get after the last stage. (Two colorings are considereddifferent if there exists some ball that is white in one coloring and black inthe other one).

Definition

    

Class:

LittleElephantAndIntervalsDiv1

Method:

getNumber

Parameters:

int, vector <int>, vector <int>

Returns:

long long

Method signature:

long long getNumber(int M, vector<int> L, vector <int> R)

(be sure your method is public)

    

 

Constraints

-

M will be between 1 and 1,000, inclusive.

-

L will contain between 1 and 50 elements,inclusive.

-

R will contain the same number of elementsas L.

-

Each element of R will be between 1 and M,inclusive.

-

i-th element of L will be between 1 andR[i], inclusive.

Examples

0)

 

    

4

{1, 2, 3}

{1, 2, 3}

Returns: 8

In the three stages the robot will choosethe color for balls number 1, 2, and 3. The choices are independent of eachother. The last, fourth ball will always remain white. Thus there are 2*2*2 = 8different colorings.

1)

 

    

3

{1, 1, 2}

{3, 1, 3}

Returns: 4

 

2)

 

    

1000

{47}

{747}

Returns: 2

 

3)

 

    

42

{5, 23, 4, 1, 15, 2, 22, 26, 13, 16, 28,13, 27, 9, 18, 4, 10, 3, 4, 4, 3, 4, 1, 18, 18, 2, 38, 4, 10, 12, 3, 30, 11,38, 2, 13, 1, 13, 18, 16, 13, 2, 14, 27, 13, 3, 26, 19, 5, 10}

{30, 41, 17, 1, 21, 6, 28, 30, 15, 19, 31,28, 35, 27, 30, 13, 31, 5, 8, 25, 40, 10, 3, 26, 23, 9, 40, 8, 40, 23, 12, 37,35, 39, 11, 34, 10, 21, 22, 21, 24, 5, 39, 27, 17, 16, 26, 35, 25, 36}

Returns: 256

 

This problem statement is the exclusive andproprietary property of TopCoder, Inc. Any unauthorized use or reproduction ofthis information without the prior written consent of TopCoder, Inc. isstrictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

 

179.86

 

#include<iostream>

#include<string>

#include<vector>

 

using namespace std;

 

class LittleElephantAndIntervalsDiv1

{

public: long long getNumber(int M, vector<int> L, vector <int> R)

         {

                            longlong ans=1;

                            intexp=0;

                            intline[1010]={0};

                            for(inti=0;i<L.size();i++)

                            {

                                     for(intj=L[i];j<=R[i];j++)

                                               line[j]=i+1;

                            }

                            for(intk=1;k<=M;k++)

                            {

                                     if((line[k]!=0)&&(line[k]!=line[k-1]))

                                               exp++;

                            }

                            ans=ans<<exp;

                            returnans;

         }

};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值