1. 程式人生 > >蝴蝶效應--Java

蝴蝶效應--Java

原題連結

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner reader = new Scanner(System.in);
		long[] s=new long[10003];
		int f,a,b,c,d;
		int i;
		int n;
		while(reader.hasNextInt()) {
			n=reader.nextInt();
			f=reader.nextInt();
			a=reader.nextInt();
			b=reader.nextInt();
			c=reader.nextInt();
			d=reader.nextInt();
			s[0]=f;
			for(i=1;i<=n;i++) {
				s[i]= (a*s[Math.max(0,i-b)] + c*s[Math.max(0,i-d)])%1000000007;
			}
			System.out.println(s[n]);
		}
		reader.close();
	}
}