标签:
直接dp即可。
按位进行dp。具体看代码。
1 #include <cstdio> 2 #include <algorithm> 3 4 using namespace std; 5 6 void Get_Val(unsigned int &Ret) 7 { 8 Ret = 0; 9 char ch; 10 while ((ch = getchar()), (ch > ‘9‘ || ch < ‘0‘)) 11 ; 12 do 13 { 14 (Ret *= 10) += ch - ‘0‘; 15 } 16 while ((ch = getchar()), (ch >= ‘0‘ && ch <= ‘9‘)); 17 } 18 19 unsigned int N; 20 unsigned int V, Temp; 21 unsigned int F[33]; 22 23 unsigned int Ans; 24 25 int main() 26 { 27 Get_Val(N); 28 while (N--) 29 { 30 Get_Val(V); 31 Temp = 0; 32 for (unsigned int i = 0;(1 << i) <= V;++i) 33 if (V & (1 << i)) 34 Temp = max(Temp, F[i]); 35 for (unsigned int i = 0;(1 << i) <= V;++i) 36 if (V & (1 << i)) 37 F[i] = max(F[i], Temp + 1); 38 } 39 for (unsigned int i = 0;i <= 32;++i) 40 Ans = max(Ans, F[i]); 41 printf("%u", Ans); 42 return 0; 43 }
【QAQ下周一开始期末考试,马上要滚粗去搞文化课了】
标签:
原文地址:http://www.cnblogs.com/Created-equal/p/5122351.html