From 710ee8853cd7ba9cdea26d5c63c86ba925942de4 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 19 May 2024 15:37:28 +0800 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=A7=84=E5=88=92=E8=A7=A3=E5=86=B3=E8=B7=B3?= =?UTF-8?q?=E6=9C=A8=E6=A1=A9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jumping-wooden-trunk/main.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 jumping-wooden-trunk/main.cc diff --git a/jumping-wooden-trunk/main.cc b/jumping-wooden-trunk/main.cc new file mode 100644 index 0000000..19bd844 --- /dev/null +++ b/jumping-wooden-trunk/main.cc @@ -0,0 +1,19 @@ +#include +using namespace std; +const int MAXN = 105; +int dp[MAXN], arr[MAXN]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + dp[i] = n - 1; + } + dp[1] = 0; + for (int i = 1; i <= n; i++) { + for (int j = i + 1; j <= i + arr[i] && j <= n; j++) { + dp[j] = min(dp[j], dp[i] + 1); + } + } + cout << dp[n] << endl; +}