AE2A动态编程

时间:2016-01-16 07:18:08

标签: dynamic-programming

我一直在努力解决这个问题:http://www.spoj.com/problems/AE2A/。我知道这背后的想法,但我得到WA。有人可以帮我弄这个吗? 我的代码是:https://ideone.com/rksW1p

for( int i=1; i<=n; i++)
{
    for( int j=1; j<=sum; j++)
    {
        for( int k=1; k<=6 && k<j; k++)
        {
            A[i][j] += A[i-1][j-k];
        }
    }
}

1 个答案:

答案 0 :(得分:0)

让模具顶部的数字为

import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;

...

public static void main(String[] args) {
    try {
        Clip clip = AudioSystem.getClip();

        File file = new File("[Some *.wav file]");
        AudioInputStream stream = AudioSystem.getAudioInputStream(file);

        clip.open(stream);
        // Control the volume
        FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
        gainControl.setValue(-20.0f);

        clip.start();
        // The clip won't keep the JVM up if you reach the "end"
        // so the sleep is merely to let it play in the demo
        Thread.sleep(1000);
        clip.close();
    } catch(Exception e) {
        e.printStackTrace();
    }
}

然后我们必须找到

的方法
x1,x2,x3...

现在,这个积分方程的解是x1+x2+x3+...+xn=sum where 1<=xi<=6 因此概率为(sum-1)C(n-1). 答案是((sum-1)C(n-1))/(6^n). 希望这会有所帮助..