<p>There is only one character <code>&#39;A&#39;</code> on the screen of a notepad. You can perform one of two operations on this notepad for each step:</p>

<ul>
	<li>Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).</li>
	<li>Paste: You can paste the characters which are copied last time.</li>
</ul>

<p>Given an integer <code>n</code>, return <em>the minimum number of operations to get the character</em> <code>&#39;A&#39;</code> <em>exactly</em> <code>n</code> <em>times on the screen</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 3
<strong>Output:</strong> 3
<strong>Explanation:</strong> Initially, we have one character &#39;A&#39;.
In step 1, we use Copy All operation.
In step 2, we use Paste operation to get &#39;AA&#39;.
In step 3, we use Paste operation to get &#39;AAA&#39;.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 0
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 1000</code></li>
</ul>

// tabulation approach
class Solution {
public:
    // // function
    // int findminsteps(int copy_count,int target,int total_count,vector<vector<int>> &dp){
    //     // base case
    //     if(target==0){
    //         return 0;
    //     }

    //     // if the value of dp[copy_count][target] is not equal to -1
    //     if(dp[copy_count][target]!=-1){
    //         return dp[copy_count][target];
    //     }

    //     // find the value of copy and paste
    //     int copy=1e9;
    //     int paste=1e9;

    //     // if the value of copy_count is less than total_count-target
    //     if(copy_count<total_count-target){
    //         // update the value of copy
    //         copy=1+findminsteps(total_count-target,target,total_count,dp);
    //     }

    //     // if the value of copy_count is less than target
    //     if(copy_count<=target){
    //         // update the value of paste
    //         paste=1+findminsteps(copy_count,target-copy_count,total_count,dp);
    //     }

    //     // return min(copy,paste)
    //     return dp[copy_count][target]=min(copy,paste);
    // }

    int minSteps(int n) {
        // edges case
        if(n==1){
            return 0;
        }

        if(n==2){
            return 2;
        }

        // create the 2d matrix dp
        vector<vector<int>> dp(n,vector<int>(n-1,0));

        // traverse the matrix
        for(int i=n-1;i>=1;i--){
            for(int j=1;j<n-1;j++){
                // find the value of copy and paste
                int copy=1e9;
                int paste=1e9;

                // if the value of copy_count is less than total_count-target
                if(i<n-j){
                    // update the value of copy
                    copy=1+dp[n-j][j];
                }

                // if the value of copy_count is less than target
                if(i<=j){
                    // update the value of paste
                    paste=1+dp[i][j-i];
                }

                // update the matrix dp
                dp[i][j]=min(copy,paste);
            }
        }

        // function call
        return dp[1][n-2] +2;
    }
};
131870