Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e1c1013

Browse files
committed
[BOJ] 1535 ์•ˆ๋…•_241025
1 parent 33f678a commit e1c1013

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.io.*;
2+
3+
public class YJ_1535 {
4+
public static void main(String[] args) throws IOException {
5+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
6+
int N = Integer.parseInt(br.readLine());
7+
8+
String[] s = br.readLine().split("\\s");
9+
String[] h = br.readLine().split("\\s");
10+
int[] exhaustion = new int[N+1];
11+
int[] happy = new int[N+1];
12+
13+
for(int i=1; i<N+1; i++){
14+
exhaustion[i] = Integer.parseInt(s[i-1]);
15+
happy[i] = Integer.parseInt(h[i-1]);
16+
}
17+
18+
final int MAX_STAMINA = 100;
19+
int[] dp = new int[MAX_STAMINA+1]; //dp[์ฒด๋ ฅ]= ์ตœ๋Œ€ ๊ธฐ์จ
20+
for(int i = 1; i < N+1; i++){
21+
for(int stamina=MAX_STAMINA; stamina > 0; stamina--) { //๋’ค์—์„œ ๋ถ€ํ„ฐ ํŠน์ • ์ฒด๋ ฅ์— ๋Œ€ํ•œ ๊ธฐ์จ์„ ๊ฐฑ์‹ ํ•˜๋ฉด์„œ ๋ฐ˜๋ณต
22+
int total = stamina-exhaustion[i]; //ํ˜„์žฌ ์ฒด๋ ฅ์—์„œ ์ฒด๋ ฅ์†Œ๋ชจ๋ฅผ ๋นผ์„œ ํ˜„์žฌ ์ƒํƒœ์—์„œ ๊ฐ€๋Šฅํ•œ ์ƒํ™ฉ์„ ๊ณ ๋ ค
23+
if (total > 0) {
24+
dp[stamina] = Math.max(dp[stamina], dp[total] + happy[i]); //"์ด๋ฏธ ๊ฐฑ์‹ ๋œ ๊ธฐ์จ" vs "ํ˜„์žฌ ์ฒด๋ ฅ์†Œ๋ชจ๋ฅผ ํฌํ•จํ•˜๊ธฐ ์œ„ํ•ด ์ด์ „ ์ƒํƒœ์˜ ๊ธฐ์จ + ํ˜„์žฌ ๊ธฐ์จ"์„ ๋น„๊ตํ•˜๊ธฐ
25+
//System.out.printf("dp[%d] = Math.max(dp[%d], dp[%d]+happy[%d])\n", stamina, stamina, total , i);
26+
//System.out.printf("%d = Math.max(%d, %d)\n\n", dp[stamina], dp[stamina], dp[total] + happy[i]);
27+
}
28+
}
29+
}
30+
31+
System.out.println(dp[MAX_STAMINA]); //์ตœ๋Œ€์ฒด๋ ฅ์ธ dp[100]์€ ํ•ญ์ƒ ์ตœ๋Œ€๊ธฐ์จ ๊ฐ’์ด ๋ณด์žฅ๋œ๋‹ค
32+
}
33+
}

0 commit comments

Comments
(0)

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /