1003 magic plants

Source: Internet
Author: User

Description

Not long ago, expedition B visited the inst desert. They found a powerful plant in the desert. It takes only one day for the plant to sprout from the seeds, and from the X Day of the sprout until the y day (including the y Day ), every day, a new seed is created, and each plant withered and died on the nth day of germination. Because expedition B had never seen such plants in the camp before, they took the seeds and placed them in their camp (this day is called The 0th day ), they wanted to know the number of M of this magical plant (not including seeds) in the camp on the nth day. But this number is too big. Now they only want to know the last 8 bits of M.
Input

The question contains multiple test data. Each test data contains only one row and contains four positive integers x, y, z, and N separated by spaces. Where 0 <x <= Y <z <= 2500,0 <n <= 2500. The question ends with four integers 0 0 0. This line does not need to be processed.
Output

Each test data output line contains a positive integer, which indicates the last 8 bits of M and the output M of m below 8 bits. The output does not contain leading 0.
Example 1 2 3 4
0 0 0 0 sample output

5

Solution:
Create two Arrays for purely simulated questions,

F [2501], F [2501]; F is used to store all surviving plant trees, and F is used to store the number of newly generated seeds. Follow the instructions to solve the problem. Pay attention to the remainder of 100000000
#include <stdio.h>long long F[2501],f[2501];int main(){int x,y,z,n,i,j;scanf("%d %d %d %d",&x,&y,&z,&n);while(x!=0 && y!=0 && z!=0 && n!=0){for(i=0;i<2502;i++){F[i]=f[i]=0;}f[0]=1;for(i=0;i<n;i++){if(i<z-1)F[i+1]=(F[i]+f[i])%100000000;else {F[i+1]=(F[i]+f[i]-f[i-z+1])%100000000;if(F[i+1]<0)F[i+1]+=100000000;}if(i<x-1)f[i+1]=0;else if (i<y-1){for(j=0;j<=i-x+1;j++){f[i+1]+=f[j];f[i+1]=f[i+1]%100000000;}}else {for(j=i-y+1;j<=i-x+1;j++){f[i+1]+=f[j];f[i+1]=f[i+1]%100000000;}}}printf("%lld\n",F[n]%100000000);scanf("%d %d %d %d",&x,&y,&z,&n);}return 0;}

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.