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;}