2023: [Usaco2005 nov]ant counting number of ants time limit:4 Sec Memory limit:64 MB
submit:85 solved:40
[Submit] [Status] [Discuss] description one day, Bessie sat bored in front of the ant hole to see the ants go in and out to carry food. Soon Bessie found that some ants were almost identical, so she thought the ants were brothers, meaning they were members of the same family. She also found that the whole ant colony sometimes had only one out foraging, sometimes a few, and sometimes even the whole ant colony came out altogether. As a result, ants have many different ways of teaming up when they go foraging. As a mathematical-minded cow, Bessie noticed that the whole ant colony consisted of a family of T (1≤t≤1000), and she numbered the families by 1 to T. There are Ni (1≤ni≤100) Ants in the family numbered I. The ants in the same family can be considered to be exactly the same. If there is a s,s+1 .... , B (1≤s≤b≤a) ants go out foraging together, how many different teams can they form? Note: As long as the number of ants in a family is different for each of the two teams, we think the two teams are different. Since Bessie could not distinguish the ants of the same family, the number of ants in all the families contained in the two teams was the same, and even if a certain family changed a few ants, Bessie would consider them to be the same team because they could not see the difference. For example, there are 5 ants in an ant colony of 3 families, the families of which belong to 1,1,2,2,3. So when they go out for food, they have the following teaming options: 1 Only ants go out there are three combinations: (1) (2) (3) 2 ants go out there are five combinations: () (+) (1,3) (2,2) (2,3) 3 ants go out there are five combinations: (1,1,2) (1,1,3) (1,2,2) (Three-way) (2,2,3) 4 Only ants go out there are three combinations: (1,2,2,3) (1,1,2,2) (1,1,2,3) 5 ants go out. There is a combination of: (1,1,2,2,3) your task is to calculate the total number of ants ' teaming schemes based on the data given. input line 1th: 4 integers separated by spaces t,a,s,b. 2nd to a+1 rows: Each line is a positive integer that is the number of the family in which an ant resides. The output outputs an integer that indicates when s to B (packageincluding S and b) when ants go out to forage, the number of different teaming schemes. Note: The combination is unordered, that is, the combination of 2,1 and combination is the same way of teaming. The final answer may be large, and you only need to output the last 6 digits of the answer. Be careful not to output leading 0 and extra spaces. Sample Input3 5 2 3
1
2
2
1
3
Sample Output10
Sample Description
2 ants go out there are 5 combinations, 3 ants go out with 5 kinds of combinations. A total of 10 combinationsHINT
Source
Silver
The problem: First obviously is a DP, and is a classic problem, with the number of ants and the most dependent on the number of families to transfer can, but such a sub-question came-such a sub-scale of data (1000 family x100 only ants = 100,000, plus x1000 family, this way must be MLE), and then was thunder to , until I saw the Hzwer god Ben Blog (otlhzwer, portal), found that the actual array of God horse can be scrolled storage, and as for the last to ask for a certain paragraph and only need to get a prefix and array ... Otlorz, feel yourself slag
(also have bzoj double experience decisive praise like tide!!! ^_^)
1/**************************************************************2Problem:20233 User:hansbug4 language:pascal5 result:accepted6Time:184Ms7Memory:2588KB8****************************************************************/9 Ten {/************************************************************** One problem:1630 A User:hansbug - language:pascal - result:accepted the time:184 Ms - memory:2588 KB - ****************************************************************/} - + Constp=1000000; - var + I,j,k,l,m,n,r:longint; AA:Array[0.. -] ofLongint; atB,c:Array[0..2,0..100500] ofLongint; - begin - readln (n,m,l,r); -Fillchar (A,sizeof (a),0); - fori:=1 toM Do - begin in Readln (j); - Inc (A[j]); to End; +b[0,0]:=1; - fori:=0 toM Doc[0, i]:=1; the fori:=1 toN Do * forj:=0 toM Do $ beginPanax NotoginsengInc (B[iMoD 2, j],c[(i-1)MoD 2, j]); - if(j-a[i]-1) >=0 ThenDec (b[iMoD 2, j],c[(i-1)MoD 2, j-a[i]-1]); theB[iMoD 2, J]:=b[iMoD 2, j]MoDp; + ifJ<>0 Then AC[iMoD 2, j]:= (c[iMoD 2, J-1]+b[iMoD 2, j])MoDP the Else +C[iMoD 2, J]:=b[iMoD 2, j]MoDp; -b[(I-1)MoD 2, j]:=0; $ End; $Writeln (((c[nMoD 2, R]-c[nMoD 2, L-1])MoDP+P)MoDp); - Readln; - End.
1630/2023: [Usaco2005 nov]ant counting number of ants