From 5bbc2ca86193d4eb1c19ebd9bf8b7eb31439fcde Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 29 Oct 2020 21:57:30 +0800 Subject: [PATCH] =?UTF-8?q?P1679=20=E7=A5=9E=E5=A5=87=E7=9A=84=E5=9B=9B?= =?UTF-8?q?=E6=AC=A1=E6=96=B9=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R40788402 --- problem/P1679/P1679.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 problem/P1679/P1679.cpp diff --git a/problem/P1679/P1679.cpp b/problem/P1679/P1679.cpp new file mode 100644 index 00000000..98001c3f --- /dev/null +++ b/problem/P1679/P1679.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +int n, ans = 999999; + +void dfs(int cnt, int k, int last) { + if (k > ans) { + return; + } + if (cnt > n) { + return; + } + if (cnt == n) { + ans = min(ans, k); + return; + } + int i = last; + while (i*i*i*i <= n - cnt) { + i++; + } + while (i >= last) { + dfs(cnt + i * i * i * i, k + 1, i); + i--; + } + return; +} + +int main() { + cin >> n; + dfs(0, 0, 1); + cout << ans << endl; + return 0; +}