結果
| 問題 |
No.1111 コード進行
|
| コンテスト | |
| ユーザー |
sca1l
|
| 提出日時 | 2020-07-20 22:10:43 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 574 ms / 2,000 ms |
| コード長 | 2,083 bytes |
| コンパイル時間 | 2,868 ms |
| コンパイル使用メモリ | 80,696 KB |
| 実行使用メモリ | 178,672 KB |
| 最終ジャッジ日時 | 2024-12-24 15:33:02 |
| 合計ジャッジ時間 | 21,281 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 48 |
ソースコード
import java.util.*;
public class Main{
static final int MOD = (int)1e9+7;
static final int MAX = 301;
static int n;
static int m;
static int k;
static ArrayList<Integer>[] graph;
static ArrayList<Integer>[] complexity;
static int[][][] memo;
public static int dfs(int now, int cmp, int cnt){
if(cmp <= k && memo[now][cmp][cnt] != -1){
return memo[now][cmp][cnt];
}
if(cnt == n || cmp > k){
//System.out.println(cnt + " : " + cmp);
if(cnt == n && cmp == k){
return 1;
}else{
return 0;
}
}
int ret = 0;
for(int i=0; i<graph[now].size(); i++){
int next = graph[now].get(i);
int cmpsum = complexity[now].get(i) + cmp;
ret += dfs(next, cmpsum, cnt+1);
ret %= MOD;
}
memo[now][cmp][cnt] = ret;
return memo[now][cmp][cnt];
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
n = Integer.parseInt(sc.next());
m = Integer.parseInt(sc.next());
k = Integer.parseInt(sc.next());
memo = new int[MAX][MAX][MAX];
for(int i=0; i<MAX; i++){
for(int j=0; j<MAX; j++){
Arrays.fill(memo[i][j], -1);
}
}
graph = new ArrayList[MAX];
complexity = new ArrayList[MAX];
for(int i=0; i<MAX; i++){
graph[i] = new ArrayList<>();
complexity[i] = new ArrayList<>();
}
for(int i=0; i<m; i++){
int p = Integer.parseInt(sc.next())-1;
int q = Integer.parseInt(sc.next())-1;
int c = Integer.parseInt(sc.next());
graph[p].add(q);
complexity[p].add(c);
}
int ans = 0;
for(int i=0; i<MAX; i++){
ans += dfs(i, 0, 1);
ans %= MOD;
}
System.out.println(ans);
}
}
sca1l