Skip to content

[λ‹€μ΄λ‚˜λ―Ή] HackerRank# The Coin Change ProblemΒ #8

@ye-yo

Description

@ye-yo

⚠️ λ‚˜μ˜ 풀이

arr[j-c[i]κΉŒμ§€ μ ‘κ·Όν–ˆμœΌλ‚˜ 더이상 풀이λ₯Ό μ§„ν–‰ν•΄λ‚˜κ°€μ§€ λͺ»ν•¨

❗️ μ˜€λ‹΅ 원인 뢄석

πŸ”‘ 풀이 핡심

μ°Έκ³  : https://www.geeksforgeeks.org/coin-change-dp-7/

  dp[0] = 1; //1을 ν• λ‹Ήν•΄μ€˜μ•Ό 경우의 수 1μ”© μΆ”κ°€ κ°€λŠ₯
  for(int i=0; i<c.size(); i++){
      for(int j= c[i]; j<=n; j++){// c[i]λΆ€ν„° μ‹œμž‘ν•˜λŠ” μ΄μœ λŠ” c[i] μ΄ν•˜μ˜ 수 μ£Όμ–΄μ§„ 동전이 μ—†μ–΄μ„œ 동전 합을 λ§Œλ“€ 수 μ—†μŒ
          dp[j] += dp[j-c[i]];         
      }
  }     

예λ₯Ό λ“€μ–΄ jκ°€ 10이고 동전 1,2,5λ₯Ό κ°€μ§€κ³  μžˆλ‹€λ©΄ 경우의 μˆ˜λŠ” λ‹€μŒκ³Ό κ°™λ‹€.

  • 1원 + dp[9]
  • 2원 + dp[8]
  • 5원 + dp[5]

이 κ°œλ…μ„ μœ„μ˜ μ½”λ“œμ— λŒ€μž…ν•˜λ©΄ λ‹€μŒκ³Ό 같이 κ³„μ‚°ν•΄λ‚˜κ°€λŠ” 것

  for(int i=0; i<c.size(); i++){
      for(int j= c[i]; j<=n; j++){
            //dp[1] += dp[1-1원], dp[2] += d[2-1원], dp[3] += d[3-1원]....
      }     
}

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions