Accepted
Code
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e7;
int dp[200];
int f(int n){
if(n == 0) return 0;
if(n < 0) return inf;
if (dp[n] != -1) return dp[n];
int x = 1 + f(n - 2);
int y = 1 + f(n - 3);
int res = min(x, y);
dp[n] = res;
return dp[n];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
memset(dp, -1, sizeof(dp));
int ans = f(n);
cout << ans;
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1106 too easy or three easy
- Contest
- Brain Booster #6
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-10-03 16:24:34
- Judged At
- 2024-11-11 02:48:29
- Judged By
- Score
- 100
- Total Time
- 1ms
- Peak Memory
- 560.0 KiB