1 solutions

  • 0
    @ 2026-11-13 19:57:17

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    int dp[10005];
    int main(){
        int n;
        cin >> n;
        memset(dp,0x3f,sizeof dp);
        dp[1] = 1;
        dp[3] = 1;
        dp[5] = 1;
        for (int i = 1;i<=n;i++){
            if (i>1) dp[i] = min(dp[i-1] + 1,dp[i]);
            if (i>3) dp[i] = min(dp[i-3] + 1,dp[i]);
            if (i>5) dp[i] = min(dp[i-5] + 1,dp[i]);
        }
        cout << dp[n];
        return 0;
    }
    
    • 1

    Information

    ID
    105
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By