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

2-InSange #6

Merged
merged 1 commit into from
Mar 18, 2024
Merged

2-InSange #6

merged 1 commit into from
Mar 18, 2024

Conversation

InSange
Copy link
Collaborator

@InSange InSange commented Mar 16, 2024

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

์•ฑ

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

10์‹œ๊ฐ„

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

์šฐ๋ฆฌ๊ฐ€ ์•Œ๊ณ  ์žˆ๋˜ DP ๋ฐฐ๋‚ญ ๋ฌธ์ œ๋ž‘ ๋น„์Šทํ–ˆ์Šต๋‹ˆ๋‹ค.
image

์ฒซ๋ฒˆ์งธ ์ ‘๊ทผ

  1. ๋ฉ”๋ชจ๋ฆฌ ๋ฐ”์ดํŠธ(M)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚˜์—ดํ•œ๋‹ค.
  2. ๋ชจ๋“  ์•ฑ(N)๋“ค์„ ๋ฐฉ๋ฌธํ•˜๋ฉด์„œ ๋ฉ”๋ชจ๋ฆฌ๋งˆ๋‹ค ๋Œ์•„๋ณธ๋‹ค.
  3. M๊ฐ’์„ ์ถฉ์กฑํ•˜๋Š” ์ตœ์†Œ ๋น„์šฉ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

ํ•ด๋‹น ๋ฐฉ๋ฒ•์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ ๋ฐ”์ดํŠธ(M)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ ‘๊ทผํ•˜์˜€์„ ๋•Œ
image
๋ฉ”๋ชจ๋ฆฌ(M)๋Š” ์ตœ์†Œ 1์—์„œ 10,000,000๋งŒํผ ๋‚˜์—ด์ด๋˜์–ด์•ผํ•˜๊ณ 
์•ฑ(N)์€ ์ตœ์†Œ 1๊ฐœ์—์„œ 100๊นŒ์ง€ ์กด์žฌํ•˜๊ธฐ์— ๋งŒ์•ฝ ๋ชจ๋“  ๋ฉ”๋ชจ๋ฆฌ ๋ฐ”์ดํŠธ๋ฅผ ์•ฑ๋“ค์ด ๋ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์˜€์„ ๊ฒฝ์šฐ
100 * 10,000,000 ๋งŒํผ ๋Œ์•„์•ผํ•˜๋ฉฐ ์‹œ๊ฐ„ ๋ณต์žก๋„ ๋ฐ ๋ฉ”๋ชจ๋ฆฌ ์ดˆ๊ณผ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

๋‘๋ฒˆ์งธ ์ ‘๊ทผ

  1. ๋น„์šฉ(c)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚˜์—ดํ•œ๋‹ค.
  2. ๋ชจ๋“  ๋น„์šฉ(c)๋ฅผ ๋”ํ•œ ๊ฐ’์„ ์ตœ๋Œ€ ํฌ๊ธฐ๋กœ ์ง€์ •ํ•œ๋‹ค.
  3. ๋น„์šฉ์„ ๊ธฐ์ ์œผ๋กœ ์•ฑ ๋ฉ”๋ชจ๋ฆฌ(m)๋ฅผ ๋ฐฐ์—ด์— ํ• ๋‹นํ•˜์—ฌ ํ˜„์žฌ ๋น„์šฉ์„ ๋บ€ ๊ฐ’์— ์•ฑ ๋ฉ”๋ชจ๋ฆฌ(m)์„ ๋”ํ•œ ๊ฐ’๊ณผ ํ˜„์žฌ ๋ฉ”๋ชจ๋ฆฌ ๋น„์šฉ์„ ๋น„๊ตํ•œ๋‹ค.
  4. ์†Œ๋ชจ๋˜๋Š” '''๋น„์šฉ(c)''' ๊ฐ’๋ณด๋‹ค ํ• ๋‹นํ•ด์ค€ ๋น„์šฉ์ด ์ž‘์„ ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•˜์—ฌ ์ตœ๋Œ€ ๋น„์šฉ์—์„œ 0์œผ๋กœ ์ ‘๊ทผํ•˜๊ฒŒ ๋” ํ•œ๋‹ค.

image
๋น„์šฉ(c)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚˜์—ดํ–ˆ์„ ๊ฒฝ์šฐ ์•ฑ(N) ๊ฐœ์ˆ˜ ๋งŒํผ ๋น„๊ต๊ฐ€ ๋”ํ•ด์ง„๋‹ค ํ–ˆ์„ ๋•Œ 100*100 ๋งŒํผ์˜ ๋ฉ”๋ชจ๋ฆฌ ๋น„์šฉ์ด ํ•„์š”ํ•˜๋‹ค.

image

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

์ฐธ๊ณ  ๋ธ”๋กœ๊ทธ :https://wisdom-990629.tistory.com/entry/C-%EB%B0%B1%EC%A4%80-7579%EB%B2%88-%EC%95%B1

@yuyu0830
Copy link
Collaborator

n ๊ฐœ์˜ ์•ฑ๊ณผ ์ตœ๋Œ€ 10,000 (100 * 100) ์˜ costs๋ฅผ ์ „๋ถ€ ํƒ์ƒ‰ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋„ค์š”. ์ฝ”๋“œ๋„ ์ปดํŒฉํŠธํ•˜๊ณ , ๋ฉ”๋ชจ๋ฆฌ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด ๋งŽ๊ธฐ ๋•Œ๋ฌธ์— cost๋กœ ์ ‘๊ทผํ•˜๋Š” ๋ฐฉํ–ฅ์ด ์žฌ๋ฐŒ์—ˆ์Šต๋‹ˆ๋‹ค.
๋ชจ๋“  cost ๋“ค์— ๋Œ€ํ•ด์„œ n๋ฒˆ ์ˆœํšŒํ•˜๋Š” ๊ฒƒ ๋ณด๋‹ค ๋‚ฎ์€ cost๋ถ€ํ„ฐ ํ™•์ •์‹œ์ผœ๋‚˜๊ฐ€๋ฉด ์•ˆ๋˜๋‚˜์š”? cost ๋ณ„๋กœ ๋”ฐ๋กœ ๋‚˜๋ˆ ์„œ ์ €์žฅํ•ด๋‘”๋‹ค๋ฉด ๊ฐ€๋Šฅ์€ ํ•  ๊ฒƒ ๊ฐ™์€๋ฐ.. ํ•œ๋ฒˆ ๋„์ „ ํ•ด๋ณด๊ณ  ๋‹ค์‹œ ์ฝ”๋ฉ˜ํŠธ ๋‹ฌ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค

Copy link
Collaborator

@yuyu0830 yuyu0830 left a comment

Choose a reason for hiding this comment

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

๊ทผ๋ฐ ๋‹ค๋“ค ๋ฐฐ์—ด์ด ์•„๋‹ˆ๋ผ ๋ฒกํ„ฐ๋ฅผ ์“ฐ๋„ค์š”? ๋ฐฐ์—ด์ด๋ž‘ ๋ฒกํ„ฐ๊ฐ€ ์ ‘๊ทผ ์†๋„๊ฐ€ ์ฐจ์ด๊ฐ€ ๋ณ„๋กœ ์—†๋‚˜์š”?

Copy link
Collaborator

@seongwon030 seongwon030 left a comment

Choose a reason for hiding this comment

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

์ตœ๋Œ€๋น„์šฉ๋ถ€ํ„ฐ ๋น„์šฉ์„ ์ค„์—ฌ๋‚˜๊ฐ€๋Š” ๋ฐฉ๋ฒ• ์ •๋ง ์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค. ์ €๋Š” ํ‰๋ฒ”ํ•œ ๋ฐฐ๋‚ญ๋ถ€ํ„ฐ ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค..

Copy link
Contributor

@dhlee777 dhlee777 left a comment

Choose a reason for hiding this comment

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

๋ฉ”๋ชจ๋ฆฌ ๋‚˜ ๋น„์šฉ์˜ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆ ์„œ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๊ตฐ์š” ๋ฒ ๋‚ญ ๋ฌธ์ œ๋Š” ํ’€์–ด๋ดค๋Š”๋ฐ ์ด ๋ฌธ์ œ๋„ ํ•œ๋ฒˆ ํ’€์–ด๋ด์•ผ๊ฒ ๋„ค์š”
์ข‹์€์ฝ”๋“œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค !

@InSange
Copy link
Collaborator Author

InSange commented Mar 18, 2024

n ๊ฐœ์˜ ์•ฑ๊ณผ ์ตœ๋Œ€ 10,000 (100 * 100) ์˜ costs๋ฅผ ์ „๋ถ€ ํƒ์ƒ‰ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋„ค์š”. ์ฝ”๋“œ๋„ ์ปดํŒฉํŠธํ•˜๊ณ , ๋ฉ”๋ชจ๋ฆฌ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด ๋งŽ๊ธฐ ๋•Œ๋ฌธ์— cost๋กœ ์ ‘๊ทผํ•˜๋Š” ๋ฐฉํ–ฅ์ด ์žฌ๋ฐŒ์—ˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  cost ๋“ค์— ๋Œ€ํ•ด์„œ n๋ฒˆ ์ˆœํšŒํ•˜๋Š” ๊ฒƒ ๋ณด๋‹ค ๋‚ฎ์€ cost๋ถ€ํ„ฐ ํ™•์ •์‹œ์ผœ๋‚˜๊ฐ€๋ฉด ์•ˆ๋˜๋‚˜์š”? cost ๋ณ„๋กœ ๋”ฐ๋กœ ๋‚˜๋ˆ ์„œ ์ €์žฅํ•ด๋‘”๋‹ค๋ฉด ๊ฐ€๋Šฅ์€ ํ•  ๊ฒƒ ๊ฐ™์€๋ฐ.. ํ•œ๋ฒˆ ๋„์ „ ํ•ด๋ณด๊ณ  ๋‹ค์‹œ ์ฝ”๋ฉ˜ํŠธ ๋‹ฌ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค

๋‚ฎ์€ cost๋ณ„๋กœ ์ƒ๊ฐ๋„ ํ•ด๋ณด๊ธดํ–ˆ๋Š”๋ฐ ๋‹ต์„ ๊ฒฐ์ •ํ•˜๋Š” ๊ฒƒ์ด memory ์ดํ•ฉ์ด๋‹ค๋ณด๋‹ˆ cost๊ฐ€ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ๋น„์šฉ์˜ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜ N์œผ๋กœ ์ฑ„์›Œ์ค˜์•ผ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค!
๋‚ฎ์€ ๋น„์šฉ, ๋†’์€ ๋ฉ”๋ชจ๋ฆฌ
๋†’์€ ๋น„์šฉ, ๋†’์€ ๋ฉ”๋ชจ๋ฆฌ
๋“ค์˜ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋กœ ๊ฐ€์ •ํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค.

@InSange
Copy link
Collaborator Author

InSange commented Mar 18, 2024

๊ทผ๋ฐ ๋‹ค๋“ค ๋ฐฐ์—ด์ด ์•„๋‹ˆ๋ผ ๋ฒกํ„ฐ๋ฅผ ์“ฐ๋„ค์š”? ๋ฐฐ์—ด์ด๋ž‘ ๋ฒกํ„ฐ๊ฐ€ ์ ‘๊ทผ ์†๋„๊ฐ€ ์ฐจ์ด๊ฐ€ ๋ณ„๋กœ ์—†๋‚˜์š”?

๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” ์ •์ , ๋™์ ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
๋ฉ”๋ชจ๋ฆฌ ์ ์œผ๋กœ๋„ ์ •์ ์œผ๋กœ ํฌ๊ฒŒ ์žก๋Š” ๊ฒƒ๋ณด๋‹ค๋Š” ๋™์ ์œผ๋กœ ํ•„์š”ํ•œ ๊ฒƒ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋ผ๊ณ  ๋ด…๋‹ˆ๋‹ค!
๋ฒกํ„ฐ ์—ญ์‹œ ์ธ๋ฑ์Šค๋กœ ์œ„์น˜๋ฅผ ์žก์•„๋‚ด๊ธฐ ๋•Œ๋ฌธ์— ์†๋„๋Š” ๋ณ„ ์ฐจ์ด ์—†๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๊ณ ์žˆ์–ด์šฉ
์žˆ๋‹ค๊ณ ํ•ด๋„ ๋ฏธ๋ฏธํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์ถ”๊ฐ€๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ vector๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋งŽ์ด๋‘๋Š” ๋ฐฑ์ค€๊ณผ ๋ฆฌํŠธ์ฝ”๋“œ์—์„œ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋‹ˆ ์ˆ™๋ จ๋„๋ฅผ ๋†’์ด๊ธฐ ์œ„ํ•ด์„œ ๊ฐ™์Šต๋‹ˆ๋‹น.

@InSange InSange merged commit f50918e into main Mar 18, 2024
1 check passed
@InSange InSange deleted the 2-InSange branch March 18, 2024 13:50
@InSange InSange changed the title 2024-03-15 ์•ฑ 2-InSange Mar 18, 2024
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.

4 participants