Title Description
Farmer John ' s N cows (1≤n≤100,000) share many similarities. In fact, FJ have been able to narrow down the list of features gkfx by he cows to a list of only K different features (1 ≤K≤30). For example, cows exhibiting feature #1 might has spots, cows exhibiting feature #2 might prefer C to Pascal, and so on.
FJ has even devised a concise-to-describe each cow in terms of their "feature ID", a single k-bit integer whose binary r Epresentation tells us the set of features exhibited by the cow. As an example, suppose a cow have feature ID = 13. Since written in binary was 1101, this means we cow exhibits features 1, 3, and 4 (reading right to left), but not feat Ure 2. More generally, we find a 1 in the 2^ (i-1) place if a cow exhibits feature I.
Always the sensitive fellow, FJ lined up cows 1..N in a long row and noticed that certain ranges of cows is somewhat "bal Anced "In terms of the features the exhibit. A contiguous range of cows I.. J is balanced if each of the K possible features are exhibited by the same number of cows in the range. FJ is curious as to the size of the largest balanced range of cows. See if you can determine it.
God Niu small r in many ways have a strong ability, specifically, he has a total of M ability, and these abilities numbered 1 to M. He has the ability to ascend one day at a time, every day there will be some ability to get a promotion, r on the daily ability to improve the use of a number, called the ability to increase the number, such as the number 13, the conversion to binary 1101, and from the right to the left, indicating that his ability to number 1,3,4 has been improved. Small r to the daily expression of the ability to raise the number of the note down, if in a continuous period of time, the small r each ability to increase the same number of times, small r will call this period of time as a balance period, for example, in a continuous 5 days, the small r each ability has increased 4 times, then this is a length of 5 of the
So, the problem comes, give the small R n days of the ability to increase the number, request the maximum length of the equilibrium period.
"Data size" for 50% of data, N <= 1000.
Input/output format
Input format:
The first line has two integer n,m, which indicates that there are n days and M abilities. Next there are n rows, each with an integer representing the ability to lift the number from 1th to n days. The ability to increase the number into binary, right-to-left each to indicate whether the corresponding ability to get a promotion on the same day.
n<=100000, m<=30
Output format:
The output has only one integer representing the length of the maximum equalization period.
Input and Output Sample input example # #:
7 37672142
Sample # # of output:
4
Description
"Sample Interpretation"
The types of abilities that are promoted each day are:
First day:
Day two: 2,3
Day Three:
Fourth day: 2
Fifth day: 1
Sixth day: 3
Seventh Day: 2
The third day to the sixth day is the longest equilibrium period of length
Because each of these four days has been raised 2 times.
/*At first thought is the interval and% (2^m-1) =0 the largest interval, and later found that it is not right, should be all stored in the state. When two numbers are the same, the number that appears between these two numbers is the same as the number that appears on each feature, otherwise it will not be the same as two numbers. Because only the rightmost number increases by the same number as all the numbers on the left, they subtract the rightmost number and appear the same. */#include<string>#include<cstring>#include<cstdio>#include<algorithm>#defineMoD 100007using namespacestd; intHash[mod+Ten][ the]; inta[mod][ to]; ints[mod][ to]; intK; BOOLCheckintTintXT) { inti; BOOLflag=true; for(i=0; i<=k-1; i++) if(s[xt][i]!=Hash[t][i])return false; return true; } intFindintXintXtintXP) { intt=x; while(hash[t][ +]!=-1) { if(!check (T,XT)) t= (t+1)%MoD; Else Break; } if(hash[t][ +]==-1) { inti; for(i=0; i<=k-1; i++) Hash[t][i]=S[xt][i]; hash[t][ -]=XP; hash[t][ +]=1; returnXP; } returnhash[t][ -]; } intMain () {intN; scanf ("%d%d",&n,&k); inti,j; intx; for(i=1; i<=n;i++) {scanf ("%d",&x); intp=0; while(x!=0) {A[i][p]=x%2; X=x/2; P++; } } for(i=1; i<=n;i++) for(j=0; j<=k-1; j + +) S[i][j]=s[i-1][j]+A[i][j]; for(i=1; i<=n;i++) for(j=k-1; j>=0; j--) S[i][j]-=s[i][0]; memset (Hash,-1,sizeof(hash));//the part of the hash is not very understanding intans=0; for(i=0; i<=n;i++) { intp=0; for(j=k-1; j>=0; j--) {p= (p*4+S[I][J])%MoD; while(p<0) p=-p; } intLoc=find (P,i,i); Ans=max (ans,i-Loc); } printf ("%d\n", ans); return 0; }
[Usaco07mar] Golden lineup balance Gold Balanced L ... (Luo gu 1360)