HDU 4628, multi-School, third game, 1008 dp

Source: Internet
Author: User

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;
}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.