There is nothing to say about this question. Enumerate the status of 2 ^ 16 directly, use 1 to get this one, and 0 to indicate not to take it. Each time you determine whether this can be taken.
[Cpp] view plaincopyprint?
# Include <iostream>
# Include <cstdio>
# Include <algorithm>
# Include <string>
# Include <cmath>
# Include <cstring>
# Include <queue>
# Include <set>
# Include <vector>
# Include <stack>
# Include <map>
# Include <iomanip>
# Define PI acos (-1.0)
# Deprecision Max 2505
# Define inf 2000000000
# Define LL (x) (x <1)
# Define RR (x) (x <1 | 1)
# Define REP (I, s, t) for (int I = (s); I <= (t); ++ I)
# Define ll long
# Define mem (a, B) memset (a, B, sizeof ())
# Define mp (a, B) make_pair (a, B)
# Define PII pair <int, int>
Using namespace std;
Inline void RD (int & ret ){
Char c;
Do {
C = getchar ();
} While (c <'0' | c> '9 ');
Ret = c-'0 ';
While (c = getchar ()> = '0' & c <= '9 ')
Ret = ret * 10 + (c-'0 ');
}
Inline void OT (int ){
If (a> = 10) OT (a/10 );
Putchar (a % 10 + '0 ');
}
Int is [20];
Int MV [1 <17];
Int dp [1 <17];
Char a [20];
Int main (){
Int t;
Cin> t;
While (t --){
Cin>;
Int l = strlen ();
Dp [0] = 0;
For (int I = 1; I <(1 <l); I ++ ){
Int aa = I;
Int num = 0;
For (int j = 0; j <l; j ++ ){
If (aa> j) & 1 ){
Is [num ++] = (int) a [j];
}
}
Bool flag = 0;
For (int j = 0; j <num/2; j ++ ){
If (is [j]! = Is [num-j-1]) {
Flag = 1;
Break;
}
}
If (! Flag) MV [I] = 1;
Else MV [I] = 0;
}
For (int I = 1; I <(1 <l); I ++ ){
If (MV [I]) dp [I] = dp [0] + 1;
Else dp [I] = inf;
For (int j = I; j> 0; -- j & = I) {// this operation is based on the standard process. At the beginning, I just sent a few times here.
If (MV [j]) {
Dp [I] = min (dp [I], dp [I-j] + 1 );
}
}
}
Cout <dp [(1 <l)-1] <endl;
}
Return 0;
}
# Include <iostream>
# Include <cstdio>
# Include <algorithm>
# Include <string>
# Include <cmath>
# Include <cstring>
# Include <queue>
# Include <set>
# Include <vector>
# Include <stack>
# Include <map>
# Include <iomanip>
# Define PI acos (-1.0)
# Deprecision Max 2505
# Define inf 2000000000
# Define LL (x) (x <1)
# Define RR (x) (x <1 | 1)
# Define REP (I, s, t) for (int I = (s); I <= (t); ++ I)
# Define ll long
# Define mem (a, B) memset (a, B, sizeof ())
# Define mp (a, B) make_pair (a, B)
# Define PII pair <int, int>
Using namespace std;
Inline void RD (int & ret ){
Char c;
Do {
C = getchar ();
} While (c <'0' | c> '9 ');
Ret = c-'0 ';
While (c = getchar ()> = '0' & c <= '9 ')
Ret = ret * 10 + (c-'0 ');
}
Inline void OT (int ){
If (a> = 10) OT (a/10 );
Putchar (a % 10 + '0 ');
}
Int is [20];
Int MV [1 <17];
Int dp [1 <17];
Char a [20];
Int main (){
Int t;
Cin> t;
While (t --){
Cin>;
Int l = strlen ();
Dp [0] = 0;
For (int I = 1; I <(1 <l); I ++ ){
Int aa = I;
Int num = 0;
For (int j = 0; j <l; j ++ ){
If (aa> j) & 1 ){
Is [num ++] = (int) a [j];
}
}
Bool flag = 0;
For (int j = 0; j <num/2; j ++ ){
If (is [j]! = Is [num-j-1]) {
Flag = 1;
Break;
}
}
If (! Flag) MV [I] = 1;
Else MV [I] = 0;
}
For (int I = 1; I <(1 <l); I ++ ){
If (MV [I]) dp [I] = dp [0] + 1;
Else dp [I] = inf;
For (int j = I; j> 0; -- j & = I) {// this operation is based on the standard process. At the beginning, I just sent a few times here.
If (MV [j]) {
Dp [I] = min (dp [I], dp [I-j] + 1 );
}
}
}
Cout <dp [(1 <l)-1] <endl;
}
Return 0;
}