Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

17-g0rnn #68

wants to merge 1 commit into from

Conversation

g0rnn
Copy link
Collaborator

@g0rnn g0rnn commented Jan 31, 2025

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

์„คํƒ• ๋ฐฐ๋‹ฌ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

10m

์ž๋ฐ”๋กœ ์–ธ์–ด๋ฅผ ๋ฐ”๊พธ์–ด ide์„ค์ •๋ถ€ํ„ฐ ์‹œ๊ฐ„์„ ์จ๋ฒ„๋ฆฌ๋Š” ๋ฐ”๋žŒ์— ์ซ„๋ ค์„œ ๋‚œ์ด๋„๋Š” ์‰ฌ์šด๊ฑธ๋กœ ์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค. ์‹ค๋ฒ„ ๋ฌธ์ œ ์ค‘ ๊ฐ€์žฅ ๋งŽ์ด ํ’€๋ฆฐ ๋ฌธ์ œ๋ฅผ ์„ ํƒํ–ˆ๋Š”๋ฐ ๋„ˆ๋ฌด ์‰ฌ์› ๋„ค์š”...

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ฌธ์ œ๋ฅผ ๋ณด๊ณ  dp๋กœ ํ’€๊ฑฐ๋‚˜ ๊ทธ๋ฆฌ๋””์ฒ˜๋Ÿผ ํ’€๋ฉด ์ข‹๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๋””๋กœ ํ’€๊ธฐ์—” ์ข€ ๋” ์ƒ๊ฐํ• ๊ฒŒ ๋งŽ์€ ๊ฑฐ ๊ฐ™์•„ dp๋ฅผ ์„ ํƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์„คํƒ• 15kg๋ฅผ ๋‹ด์„ ๋•Œ 3kg๋ด‰์ง€๋ฅผ ์„ ํƒํ• ์ง€ 5kg๋ด‰์ง€๋ฅผ ์„ ํƒํ• ์ง€ ๊ณ ๋ฅด๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” 12kg์„ ์ตœ์†Œํ•œ์œผ๋กœ ๋‹ด์€ ๋ด‰์ง€์ˆ˜์— 1์„ ๋”ํ• ๊ฑด์ง€, 10kg๋ฅผ ์ตœ์†Œํ•œ์œผ๋กœ ๋‹ด์€ ๋ด‰์ง€์ˆ˜์— 1์„ ๋”ํ• ๊ฑด์ง€ ๊ณ ๋ฅด๋ฉด ๋ฉ๋‹ˆ๋‹ค.

MinBasket[i] = min(MinBasket[i-3], minBasket[i-5]) + 1

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

์ž๋ฐ”๋กœ ํ‘ธ๋‹ˆ ์•ฝ๊ฐ„์˜ ์ œํ•œ์ด ์žˆ๋”๊ตฐ์š”. ํด๋ž˜์Šค๋ช…์ด Main์ด๋˜๊ฐ€ ๋ชปํ‘ธ๋Š” ๋ฌธ์ œ๊ฐ€ ์กด์žฌํ•œ๋‹ค๋˜๊ฐ€.. ๊ทธ๋ž˜์„œ ๋‚ด๊ฐ€ cpp๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์„ ํƒํ–ˆ์—ˆ๊ตฌ๋‚˜... ๋ฐฑ์ค€ ์ž๋ฐ” ํŒ์„ ๊ณต์œ ํ•˜๋ฉฐ ์ด๋ฒˆ pr ๋งˆ์น˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๋ฐฑ์ค€ ์ž๋ฐ” ํŒ


int n = sc.nextInt();

int[] dp = new int[5001];
Copy link
Collaborator

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);
        }
    }
}
์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ๊ฐ€๋Šฅํ–ˆ๋„ค์š”. ์ €๋Š” ์ด ๋ฐฉ๋ฒ•์ด ์ƒ๊ฐ ์•ˆ๋‚˜์„œ dp๋กœ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค.. ํ•œ ์ˆ˜ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค:)

Copy link
Collaborator

@kangrae-jo kangrae-jo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ˆ์ „์— dp ๊ณต๋ถ€ํ• ๋•Œ ํ’€์–ด๋ดค๋˜ ๋ฌธ์ œ ๊ฐ™์•„์š”
์žฌ๋ฐŒ๊ฒŒ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค.

์ €๋„ ์ž๋ฐ”๋กœ ํ’€๊ณ ์‹ถ์€ ๋งˆ์Œ์ด ๋“œ๋„ค์š”

์ฝ”๋“œ๋Š” ๊ท ํ˜ธ๋‹˜๊ณผ ๋™์ผํ•ฉ๋‹ˆ๋‹ค!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants