結果

問題 No.314 ケンケンパ
ユーザー 37zigen
提出日時 2016-03-25 20:15:47
言語 Java
(openjdk 23)
結果
AC  
実行時間 150 ms / 1,000 ms
コード長 590 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 74,736 KB
実行使用メモリ 60,308 KB
最終ジャッジ日時 2024-10-02 00:50:16
合計ジャッジ時間 5,480 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder314;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long[] dp=new long[n+1];
		long mod=(long)Math.pow(10, 9)+7;
		dp[0]=0;///ケン・ケン・パ ケン・パ
		dp[1]=0;
		if(n==1){
			System.out.println(1);
			return;
		}
		dp[2]=1;
		if(n==2){
			System.out.println(2);
			return;
		}
		dp[3]=1;
		if(n==3){
			System.out.println(2);
			return;
		}
		for(int i=4;i<=n;i++){
			dp[i]=(dp[i-2]+dp[i-3])%mod;
		}
		System.out.println((dp[n]+dp[n-1]+dp[n-2])%mod);
	}
}
0