P1400 Tower, P1400

Source: Internet
Author: User

P1400 Tower, P1400
Description

There are N (2 <= N <= 600000) blocks of bricks, to build a n-layer Tower, requirement: If brick A is on Brick B, then A cannot be longer than B's Length + D. There are several ways to output the value of mod 1000000009.

Input/Output Format Input Format:

The first line: N, D the second line: N number, indicating the length of each brick.

Output Format:

Number of solutions, output mod 1000000009

Input and Output sample Input example #1:
4 11 2 3 100
Output sample #1:
4

Multiplication principle

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #define lli long long int  6 #include<algorithm> 7 using namespace std; 8 const int MAXN=600001; 9 const int mod=1000000009;10 int read(int & n)11 {12     char c='.';int x=0,flag=0;13     while(c<'0'||c>'9')14     {c=getchar();  if(c=='-')flag=1; }15     while(c>='0'&&c<='9')16     {x=x*10+(c-48);c=getchar();}17     if(flag==1)n=-x;else n=x;18 }19 int n,d;20 int a[MAXN];21 lli ans=1;22 int top=1;23 int maxn=1;24 int main()25 {26     read(n);read(d);27     for(int i=1;i<=n;i++)28         read(a[i]);29     sort(a+1,a+n+1);30     for(int i=2;i<=n;i++)31     {32         while(a[i]>a[top]+d)33         {34             top++;35         }36         ans=ans*(i-top+1);37         ans=ans%mod;38     }39     //printf("%d",ans);40     cout<<ans;41     return 0;42 }

 

 

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.