BZOJ[2023/1630]: [Usaco2005 nov]ant counting number ant dp+ scrolling array

Source: Internet
Author: User
2023: [Usaco2005 nov]ant counting number of antsTime Limit:4 Sec Memory limit:64 MB submit:180 solved:110 [Submit][status][discuss] DescriptionOne day, Bessie sat bored in front of the ant hole to watch 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 to forage 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 foraging, they have the following teaming options: • 1 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 with five combinations: (1,1,2) (1,1,3) (+ , 2) (2,2,3) • 4 ants go out there are three combinations: (1,2,2,3) (1,1,2,2) (1,1,2,3) • 5 ants go out with a combination: (1,1,2,2,3) your task is to calculate the total number of ants ' teaming programs based on the data given. InputLine 1th: 4 integer t,a,s,b separated by a space. 2nd to a+1: Each line is a positive integer that is the number of the family in which an ant resides. OutputOutputs an integer that indicates the number of different teaming scenarios when s to B (including S and b) only ants go out to forage. 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 Input5 2 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 combinations The following:
DP:DP[I][J] represents the first I ant race, there are j ants go out to forage for the number of programs.
Dp[i][j]=sigma (Dp[i][k]) (J-W[I]<=K<=J)
Because the array does not fit, you need to scroll through the array


Code from Huang:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL Long long
using namespace std;
const int inf=2137960000;
const int mod=1000000;
const int n=100005;
int n,m,l,r;
int w[n],f[2][n],s[2][n];
int main ()
{
	scanf ("%d%d%d%d", &n,&m,&l,&r);
	int x;
	for (int i=1;i<=m;i++)
	{
		scanf ("%d", &x);
		w[x]++;
	}
	F[0][0]=1;
	for (int i=0;i<=m;i++) s[0][i]=1;
	int i,j;
	for (i=1;i<=n;i++) for
	(j=0;j<=m;j++)
	{
		f[i&1][j]+=s[(i-1) &1][j];
		if (j-w[i]-1>=0) (f[i&1][j]-=s[(i-1) &1][j-w[i]-1])%=mod;
		if (j==0) s[i&1][j]=f[i&1][j];
		else s[i&1][j]= (s[i&1][j-1]+f[i&1][j])%mod;
		f[(i-1) &1][j]=0;
	}
	printf ("%d\n", (s[n&1][r]-s[n&1][l-1]%mod+mod)%mod);
}


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.