結果

問題 No.30 たこやき工場
ユーザー kou6839kou6839
提出日時 2014-11-24 18:18:05
言語 Java
(openjdk 23)
結果
AC  
実行時間 226 ms / 5,000 ms
コード長 1,110 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 77,428 KB
実行使用メモリ 45,452 KB
最終ジャッジ日時 2024-12-21 05:18:33
合計ジャッジ時間 6,015 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.*;
 

public class Main {
	static int[] dp;
	static int[][] in;
	static int dfs(int i,int n){
		if(i==n) return 1;
		if(dp[i]!=0) return dp[i]; 
		int res=0;
		for(int j=1;j<101;j++){
			if(in[i][j]!=0){
				res+=in[i][j]*dfs(j,n);
			}
		}
		return dp[i]=res;
	}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        dp=new int[101];
        int[] ans =new int[101];
        in = new int[101][101];
        for(int i=0;i<m;i++){
        	int a = sc.nextInt();
        	int b = sc.nextInt();
        	int c = sc.nextInt();
        	in[a][c]=b;
        }
        Arrays.fill(ans, -1);
        for(int i=1;i<n;i++){
        	boolean flag=true;
        	for(int j=1;j<101;j++){
        		if(in[j][i]!=0){
        			System.out.println(0);
        			flag=false;
        			break;
        		}
        	}
        	if(flag){
        		System.out.println(dfs(i,n));
        	}
        	
        }
        
        
    }
}
0