<p>There is a strange printer with the following two special properties:</p>

<ul>
	<li>The printer can only print a sequence of <strong>the same character</strong> each time.</li>
	<li>At each turn, the printer can print new characters starting from and ending at any place and will cover the original existing characters.</li>
</ul>

<p>Given a string <code>s</code>, return <em>the minimum number of turns the printer needed to print it</em>.</p>

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

<pre>
<strong>Input:</strong> s = &quot;aaabbb&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> Print &quot;aaa&quot; first and then print &quot;bbb&quot;.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;aba&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> Print &quot;aaa&quot; first and then print &quot;b&quot; from the second place of the string, which will cover the existing character &#39;a&#39;.
</pre>

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

<ul>
	<li><code>1 &lt;= s.length &lt;= 100</code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

class Solution {
public:
    int t[101][101];
    int dp(string s,int l,int r){
        if(l>r) return 0;
        if(l==r) return 1;
        // if(r-l+1==3 && s[l]==s[r]) return 2; 
        if(t[l][r]!=-1) return t[l][r];
        int ans = 0;
        int y=l; int fin = 1+dp(s,l+1,r);
        for(int i=l+1;i<=r;i++){
            if(s[y]==s[i]){
                // ans+=dp(s,y+1,i-1);
                // y=i;
                fin = min(fin,dp(s,y+1,i-1)+dp(s,i,r));
            }
        }
        return t[l][r] = fin;
    }
    int strangePrinter(string s) {
        int n = s.size();
        memset(t,-1,sizeof(t));
        string s1="";s1+=s[0];
        for(int i=1;i<n;i++){
            if(s[i]!=s[i-1]) s1=s1+s[i];
        }
        s = s1;
        n=s1.size();
        return dp(s,0,n-1);
    }
};
73182