結果
問題 |
No.269 見栄っ張りの募金活動
|
ユーザー |
|
提出日時 | 2018-07-05 20:41:44 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 116 ms / 5,000 ms |
コード長 | 1,934 bytes |
コンパイル時間 | 2,291 ms |
コンパイル使用メモリ | 79,804 KB |
実行使用メモリ | 63,560 KB |
最終ジャッジ日時 | 2024-07-01 02:41:07 |
合計ジャッジ時間 | 4,982 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashMap; import java.util.StringTokenizer; public class Main { static final int mod = 1000*1000*1000 + 7; static int dp[][]; static int n,s,k; public static int solve(int ind,int s) { //System.out.println(s); if (s < 0) { return 0; } if (ind == n) { return s == 0 ? 1 : 0; } if (dp[ind][s] != -1) { return dp[ind][s]; } int ret = 0; ret += solve(ind + 1,s); ret %= mod; ret += solve(ind,s - (n - ind)); ret %= mod; return dp[ind][s] = ret; } public static void main(String[]args) throws Throwable { Scanner sc = new Scanner(System.in); n = sc.nextInt(); s = sc.nextInt(); k = sc.nextInt(); dp = new int[n][s + 1]; for (int i = 0 ; i < n ; ++i) { s -= i * k; } for (int i = 0 ; i < n ; ++i) { Arrays.fill(dp[i], -1); } System.out.println(solve(0,s)); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }