2023: [usaco 2005 Nov] ant Counting Number ant time limit: 4 sec memory limit: 64 MB
Submit: 56 solved: 16
[Submit] [Status] Description one day, Bessie sat bored in front of the ant cave and watched the ants go in and out to carry food. soon Bessie found that some of the ants looked almost identical, so she thought those ants were brothers, that is, they were members of the same family. she also found that sometimes only one of the entire ant group came out for food, sometimes a few, and sometimes the whole ant colony came out together. in this way, there are many types of team-up solutions for ant financial when traveling for food. as a math-minded cow, Bessie noticed that the entire ant group was composed of T (1 ≤ T ≤ 1000) families, which were numbered from 1 to T. ni (1 ≤ Ni ≤ 100) is an ant in the family numbered I. the ant financial in the same family can be considered completely the same. if a total of S, S + 1 ...., B (1 ≤ S ≤ B ≤ A) How many different teams can an ant group work together for food? Note: As long as the number of ants in a family is different between the two teams, we think the two teams are different. because Bessie could not tell the ants of the same family, when the numbers of all the families included in the two teams are the same, even if a family had changed several ants, bessie will think of them as the same team because they cannot see the difference. for example, there are five ants in a group composed of three families:, and 3. so when they go out for food, they have the following teams: · 1 ant has three combinations: (1) (2) (3) 2 ant has five combinations: (1, 1) (1, 2) (1, 3) (2, 2) (2, 3) 3 ant financial has five combinations: (1, 1, 2) (1, 1, 3) (1, 2) (1, 2, 3) (, 3) · Four ants have three combinations: (,) · five ants have one combination, 2, 2, 3) Your task is to calculate the total number of teams of the ant financial team based on the given data. row 1st of input: Four integers t, A, S, and B separated by spaces. rows 2nd to a + 1: each row is a positive integer and the number of the family of an ant. output outputs an integer, indicating the number of different team-up solutions when s to B (including S and B) only go out for food by ANT Financial. note: The combination is unordered. That is to say, the combination of and the combination of is the same way of teaming. the final answer may be large. You only need to output the last six digits of the answer. do not output leading 0 and extra spaces. sample input5 2 3
Sample output 10
Example
There are 5 combinations of 2 ants going out, and 5 combinations of 3 ants going out. There are 10 types of hint combinations.
Source
Silver
Question: Isn't this the number of combinations of multiple sets? What can we do with the refresh principle ?????? Later, I thought about DP... F [I] [J] = sigma (F [I-1] [k]) 0 <j-k <= G [I] Scroll + prefix and you can code:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 1000000+100014 #define maxm 500+10015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 #define for0(i,n) for(int i=0;i<=(n);i++)19 #define for1(i,n) for(int i=1;i<=(n);i++)20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)22 #define mod 100000023 using namespace std;24 inline int read()25 {26 int x=0,f=1;char ch=getchar();27 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}28 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}29 return x*f;30 }31 int n,m,x,y,tmp,t=0,ans,f[2][maxn],g[maxn];32 int main()33 {34 freopen("input.txt","r",stdin);35 freopen("output.txt","w",stdout);36 n=read();m=read();x=read();y=read();37 for1(i,m)g[read()]++; 38 f[0][0]=1;f[1][0]=1;39 for1(i,n)40 {41 tmp=0;t=1-t;42 for1(j,y)43 {44 tmp=(tmp+f[1-t][j-1])%mod;45 if(j>g[i])tmp=(tmp-f[1-t][j-g[i]-1]+mod)%mod;46 f[t][j]=(f[1-t][j]+tmp)%mod;47 }48 }49 ans=0;50 for2(i,x,y)ans=(ans+f[t][i])%mod;51 printf("%d\n",ans);52 return 0;53 }
View code
Bzoj2023: [usaco2005 Nov] ant Counting Number ant