Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- ์ฐ์ ์์ ํ
- dynamic debugging
- Spring
- ๊ตฌํ
- ๋ฌธ์์ด
- thymeleaf
- dfs
- Reversing
- DP
- ์คํ
- ์๋ฎฌ๋ ์ด์
- web
- JPA
- BFS
- ์ด๋ถ ํ์
- OS
- GCP
- ๊ทธ๋ฆฌ๋
- java
- CVE
- ๋์ ํฉ
- error
- ๋ฐ์ดํฌ์คํธ๋ผ
- ๋ถํ ์ ๋ณต
- c++
- ์ฌ๊ท
- ๋ฐฑํธ๋ํน
- ์์ ์ ๋ ฌ
- ์ต๋จ ๊ฒฝ๋ก
- ๋งต
Archives
- Today
- Total
hades
[Baekjoon] 17626๋ฒ: Four Squares ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/17626
๐ ์ค๊ณ
๋ชจ๋ ์์ฐ์๋ ๋ท ํน์ ๊ทธ ์ดํ์ ์ ๊ณฑ์์ ํฉ์ผ๋ก ํํํ ์ ์์ผ๋ฏ๋ก, ๊ทธ ์์ฐ์๋ฅผ ์ด๋ฃจ๋ ์ ๊ณฑ์๋ค์ ์๋ ๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ์ ์ด์ฉํ์ฌ ๊ตฌํ ์ ์๋ค.
์๋ฅผ ๋ค์ด, 61 = 5^2 + 6^2์ด๋ฏ๋ก 5^2์ ์ต์ ์ ๊ณฑ์ ๊ฐ์์ธ 1๊ณผ 6^2์ ์ต์ ์ ๊ณฑ์ ๊ฐ์์ธ 1์ ๋ํด ์ ๊ณฑ์ 2๊ฐ๋ฅผ ์ด์ฉํ์ฌ ๊ตฌํ ์ ์๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int n;
vector<int> dp(50001, 1e9 + 7);
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
dp[0] = 0;
for (int i = 0; i <= n; i++) {
for (int j = 1; j * j <= n; j++) {
if (i + j * j > n) {
continue;
}
dp[i + j * j] = min(dp[i + j * j], dp[i] + 1);
}
}
cout << dp[n] << "\n";
return 0;
}
๐ ๋ฉ๋ชจ
๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ์ ํ ๋๋ ํญ์ ์ด๊น๊ฐ๊ณผ ๋ฒ์ ์ค์ ์ ์ ์ํด์ผ ํ๋ค.
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 28702๋ฒ: FizzBuzz (0) | 2024.07.31 |
---|---|
[Baekjoon] 30804๋ฒ: ๊ณผ์ผ ํํ๋ฃจ (0) | 2024.07.30 |
[Baekjoon] 14500๋ฒ: ํ ํธ๋ก๋ฏธ๋ ธ (1) | 2024.07.26 |
[Baekjoon] 11726๋ฒ: 2xn ํ์ผ๋ง (0) | 2024.07.26 |
[Baekjoon] 11724๋ฒ: ์ฐ๊ฒฐ ์์์ ๊ฐ์ (0) | 2024.07.25 |