File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class boj2624 {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static StringTokenizer st;
8+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
9+ static int nextInt() {return Integer . parseInt(st. nextToken());}
10+
11+ public static void main(String [] args) throws Exception {
12+ nextLine();
13+ int T = nextInt();
14+ nextLine();
15+ int k = nextInt();
16+ Coin [] coins = new Coin [k+ 1 ];
17+ int [][] dp = new int [T + 1 ][k+ 1 ];
18+
19+ for (int i = 1 ; i <= k; i++ ) {
20+ nextLine();
21+ int p = nextInt();
22+ int n = nextInt();
23+ coins[i] = new Coin (p, n);
24+ }
25+ for (int i = 1 ; i <= k; i++ ) {
26+ int val = coins[i]. val;
27+ int cnt = coins[i]. cnt;
28+ dp[0 ][i - 1 ] = 1 ;
29+
30+ for (int j = 1 ; j <= cnt; j++ ) {
31+ for (int z = val * j; z <= T ; z++ ) {
32+ dp[z][i] += dp[z - (val * j)][i - 1 ];
33+ }
34+ }
35+
36+ for (int j = 1 ; j <= T ; j++ ) {
37+ dp[j][i] += dp[j][i - 1 ];
38+ }
39+ }
40+
41+ System . out. println(dp[T ][k]);
42+ }
43+ static class Coin {
44+ int val, cnt;
45+ Coin (int val , int cnt ) {
46+ this . val = val;
47+ this . cnt = cnt;
48+ }
49+ }
50+ }
51+ ```
You can’t perform that action at this time.
0 commit comments