Acm:nbut 1646 Internet of Lights and switches-binary +map+vector

Source: Internet
Author: User
Tags switches

nbut 1646Internet of Lights and switches

Time Limit: 5000MS Memory Limit:65535KB 64bit IO Format:

You is a fan of "Internet of Things" (IoT, IoT), so you build a nice Internet of Lights and switches in your huge mansion. Formally, there is n lights and m switches, each switch controls one or more lights, i.e. pressing that switch flips the Status of those lights (On->off, Off->on).

Initially, all the lights is on. Your task is to count the number of ways to turn off, the lights by pressing some consecutive switches. Each switch should is pressed more than once. There is only one restriction:the number of switches you pressed should be between A and B (inclusive).


Input

There'll is at the most test cases. Each test case is begins with a line containing four integers n, m, A, B (2<=n<=50, 1<=a<=b<=m<=300000). Each of the following m lines contains a is in string of length n. The i-th character is 1 if, and only if, switch controls the i-th light. The size of the whole input file does not exceed 8MB.

Output

For each test case, print the case number, and the number of ways to turn off all the lights.

Sample Input

Sample Output

Case 1:3case 2:0case 3:2

#include "algorithm" #include "iostream" #include "CString" #include "cstdlib" #include "Cstdio" #include "string" # Include "vector" #include "queue" #include "Cmath" #include "map" using namespace std;typedef long long LL; #define MEMSET (X, Y) memset (x,y,sizeof (x)) #define MEMCPY (x, y) memcpy (x,y,sizeof (×)) #define FK (x) cout<< "[" <<x<< "]\n "#define BIGFOR (t) for (int qq=1;qq<= t; qq++) #define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1ll Light_now [300006];int Main () {char s[123];int n,m,a,b;int qq=1;  ll Light_change;while (~scanf ("%d%d%d%d", &n,&m,&a,&b)) {map< LL, vector<int> > MP; LL saves the state of the switch, and the vector saves all the starting points that can be pressed to this state. Mp.clear (); light_now[0]=0;mp[0].push_back (0); for (int i=1; i<=m; i++) {scanf ("%s", s);//FK (s); Light_change=0;for ( int j=0; j<n; J + +) {if (s[j]== ' 1 ') light_change+= (1ll<<j);//50-digit number to save the state of the Lamp}//FK (light_change); light_now[i]=light_change^ LIGHT_NOW[I-1]; Take the reverse, now the state of the switch. FK (Light_now[i]); Mp[light_now[i]].push_back (i); Each key that needs to be pressed can be pressed to thisAll beginnings of a state are saved. }int ans=0;for (int i=1; i<=m; i++) {LL t= ((~light_now[i)) & ((1ll<<n)-1));//key to be pressed if (!mp[t].empty ()) {// int X=mp[t].front ();//mp[t].pop ();//if (x>=a&&x<=b) ans++;int L=lower_bound (Mp[t].begin (), Mp[t].end (  ), I-b)-mp[t].begin ();  Find the lower boundary int R=upper_bound (Mp[t].begin (), Mp[t].end (), i-a)-mp[t].begin ();  Find Upper boundary ans+=r-l; Record all the possibilities. }}printf ("Case%d:", qq++);p rintf ("%d\n", ans); return 0;} /*/2 4 1 4011011002 4 3 3011011006 3 1 3101001010110101001/*/

  

Acm:nbut 1646 Internet of Lights and switches-binary +map+vector

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.