蝴蝶效应(Java版 Python版后期上新)

Problem Description

蝴蝶效应是气象学家洛伦兹1963年提出来的。其大意为:一只南美洲亚马孙河流域热带雨林中的蝴蝶,偶尔扇动几下翅膀,可能在两周后引起美国德克萨斯引起一场龙卷风。其原因在于:蝴蝶翅膀的运动,导致其身边的空气系统发生变化,并引起微弱气流的产生,而微弱气流的产生又会引起它四周空气或其他系统产生相应的变化,由此引起连锁反应,最终导致其他系统的极大变化。此效应说明,事物发展的结果,对初始条件具有极为敏感的依赖性,初始条件的极小偏差,将会引起结果的极大差异。

我们将问题简化为方程 f(x) = (a*f(max(0,x-b)) + c*f(max(0,x-d)))%1000000007。

现在给出不同的f(0)和n以及参数a,b,c,d,计算出f(n)。

Input

多组输入。

对于每组数据,有六个个整数n,f0(1 <= n <= 10000,1 <= f0 <= 10000),a,b,c,d(1 <= a,b,c,d <= 10000)。

Output

对于每组数据输出f(n)。

Sample Input

1 2 3 4 5 6

Sample Output

16
import java.util.Scanner;
public class Main{
    static long f[] = new long[10010];
    final static long mod = 1000000007;
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n,a,b,c,d,i;
        while(in.hasNext()){
            n = in.nextInt();
            f[0]=in.nextInt();
            a = in .nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            for(i = 1;i <= n;i++ ) {
                f[i] = (a*f[Math.max(0, i-b)] + c*f[Math.max(0, i-d )])% mod;
            }
            System.out.println(f[n]);
        }
    }
}

Java给我的感觉就是,可以用各种方便好用的方法,方便运算

猜你喜欢

转载自blog.csdn.net/qq_30277453/article/details/82845282