-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
17-g0rnn #68
base: main
Are you sure you want to change the base?
Conversation
|
||
int n = sc.nextInt(); | ||
|
||
int[] dp = new int[5001]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dp๋ก ํธ์
จ๊ตฐ์.
์ ๋ ๊ทธ๋ฅ ๋ฌด์ํ๊ฒ ํ์์ต๋๋ค.
java code
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int y = 0;
int min = Integer.MAX_VALUE;
if (n % 3 == 0) {
min = Math.min(min, n/3);
}
for (int x = 0; 3*x <= n; x++) {
if ((n - 3*x)%5 == 0) {
y = (n - 3*x)/5;
min = Math.min(min, x+y);
}
}
if (min == Integer.MAX_VALUE) {
System.out.println(-1);
} else {
System.out.println(min);
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ตฌํ๋ ๋ฐฉ๋ฒ์ด ๊ฐ๋ฅํ๋ค์. ์ ๋ ์ด ๋ฐฉ๋ฒ์ด ์๊ฐ ์๋์ dp๋ก ํ์์ต๋๋ค.. ํ ์ ๋ฐฐ์๊ฐ๋๋ค:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์์ ์ dp ๊ณต๋ถํ ๋ ํ์ด๋ดค๋ ๋ฌธ์ ๊ฐ์์
์ฌ๋ฐ๊ฒ ํ์์ต๋๋ค.
์ ๋ ์๋ฐ๋ก ํ๊ณ ์ถ์ ๋ง์์ด ๋๋ค์
์ฝ๋๋ ๊ท ํธ๋๊ณผ ๋์ผํฉ๋๋ค!
๐ ๋ฌธ์ ๋งํฌ
์คํ ๋ฐฐ๋ฌ
โ๏ธ ์์๋ ์๊ฐ
10m
์๋ฐ๋ก ์ธ์ด๋ฅผ ๋ฐ๊พธ์ด ide์ค์ ๋ถํฐ ์๊ฐ์ ์จ๋ฒ๋ฆฌ๋ ๋ฐ๋์ ์ซ๋ ค์ ๋์ด๋๋ ์ฌ์ด๊ฑธ๋ก ์ ํํ์ต๋๋ค. ์ค๋ฒ ๋ฌธ์ ์ค ๊ฐ์ฅ ๋ง์ด ํ๋ฆฐ ๋ฌธ์ ๋ฅผ ์ ํํ๋๋ฐ ๋๋ฌด ์ฌ์ ๋ค์...
โจ ์๋ ์ฝ๋
๋ฌธ์ ๋ฅผ ๋ณด๊ณ dp๋ก ํ๊ฑฐ๋ ๊ทธ๋ฆฌ๋์ฒ๋ผ ํ๋ฉด ์ข๊ฒ ๋ค๊ณ ์๊ฐํ์ต๋๋ค. ๊ทธ๋ฆฌ๋๋ก ํ๊ธฐ์ ์ข ๋ ์๊ฐํ ๊ฒ ๋ง์ ๊ฑฐ ๊ฐ์ dp๋ฅผ ์ ํํ์์ต๋๋ค.
๋ง์ฝ ์คํ 15kg๋ฅผ ๋ด์ ๋ 3kg๋ด์ง๋ฅผ ์ ํํ ์ง 5kg๋ด์ง๋ฅผ ์ ํํ ์ง ๊ณ ๋ฅด๋ฉด ๋ฉ๋๋ค. ์ด๋ 12kg์ ์ต์ํ์ผ๋ก ๋ด์ ๋ด์ง์์ 1์ ๋ํ ๊ฑด์ง, 10kg๋ฅผ ์ต์ํ์ผ๋ก ๋ด์ ๋ด์ง์์ 1์ ๋ํ ๊ฑด์ง ๊ณ ๋ฅด๋ฉด ๋ฉ๋๋ค.
MinBasket[i] = min(MinBasket[i-3], minBasket[i-5]) + 1
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
์๋ฐ๋ก ํธ๋ ์ฝ๊ฐ์ ์ ํ์ด ์๋๊ตฐ์. ํด๋์ค๋ช ์ด Main์ด๋๊ฐ ๋ชปํธ๋ ๋ฌธ์ ๊ฐ ์กด์ฌํ๋ค๋๊ฐ.. ๊ทธ๋์ ๋ด๊ฐ cpp๋ก ์๊ณ ๋ฆฌ์ฆ์ ์ ํํ์๊ตฌ๋... ๋ฐฑ์ค ์๋ฐ ํ์ ๊ณต์ ํ๋ฉฐ ์ด๋ฒ pr ๋ง์น๊ฒ ์ต๋๋ค.
๋ฐฑ์ค ์๋ฐ ํ