1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "list" #include "queue" using namespace std; #define MAXN 400006
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedef long long ll; int n , k; int A[MAXN] , w[MAXN]; int dp[18][1 << 18][2][2];
inline void chkmx( int& x , int y ) { x = ( x > y ? x : y ); }
void solve() { cin >> n >> k; rep( i , 1 , k ) scanf("%d",A + i) , -- A[i] , w[A[i]] = 1; memset( dp , -0x3f , sizeof dp ); rep( i , 0 , ( 1 << n - 1 ) - 1 ) { dp[1][i][w[i << 1]][w[i << 1 | 1]] = w[i << 1] | w[i << 1 | 1]; dp[1][i][w[i << 1 | 1]][w[i << 1]] = w[i << 1] | w[i << 1 | 1]; } int s , t; rep( i , 2 , n ) { s = ( 1 << n - i ) - 1; rep( j , 0 , s ) rep( wl , 0 , 1 ) rep( dl , 0 , 1 ) rep( wr , 0 , 1 ) rep( dr , 0 , 1 ) { t = dp[i - 1][j << 1][wl][dl] + dp[i - 1][j << 1 | 1][wr][dr]; chkmx( dp[i][j][wl | wr][dl | dr] , t + ( ( dl | dr ) << 1 ) + ( wl | wr ) ); if( wl | wr ) chkmx( dp[i][j][wl + wr - 1][1] , t + ( dl | dr ) + ( wl | wr ) + 1 ); } } int mx = 0; rep( wl , 0 , 1 ) rep( dl , 0 , 1 ) chkmx( mx , dp[n][0][wl][dl] + ( wl | dl ) ); cout << mx << endl; }
signed main() {
solve(); }
|