标签:span open ide break view mes sizeof f11 else
Dp[i + 1][j >> 1][k - 1] = min(Dp[i + 1][j >> 1][k - 1], Dp[i][j][k]);
int Lim = INF; for (int h = 0; h < 8; ++h) { if ((j >> h) & 1)continue; if (i + h > Lim)break; Lim = min(Lim, i + h + B[i + h]); Dp[i][j | (1 << h)][h + 8] = min(Dp[i][j | (1 << h)][h + 8], Dp[i][j][k + 8] + (i + k ? T[i + k] ^ T[i + h] : 0)); }
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 using namespace std; 6 7 const int Maxn = 1005, INF = 1e9 + 7; 8 int N, M, T[Maxn], B[Maxn], Dp[Maxn][1 << 8][20]; 9 10 int main() 11 { 12 scanf("%d", &M); 13 while (M--) 14 { 15 scanf("%d", &N); 16 memset(Dp, 0x7f, sizeof Dp); 17 Dp[1][0][7] = 0; 18 for (int i = 1; i <= N; ++i) scanf("%d %d", T + i, B + i); 19 for (int i = 1; i <= N; ++i) 20 for (int j = 0; j < (1 << 8); ++j) 21 for (int k = -8; k < 8; ++k) 22 { 23 if (Dp[i][j][k + 8] >= INF)continue; 24 if (j & 1) Dp[i + 1][j >> 1][k + 7] = min(Dp[i + 1][j >> 1][k + 7], Dp[i][j][k + 8]); 25 else 26 { 27 int Lim = INF; 28 for (int h = 0; h < 8; ++h) 29 { 30 if ((j >> h) & 1)continue; 31 if (i + h > Lim)break; 32 Lim = min(Lim, i + h + B[i + h]); 33 Dp[i][j | (1 << h)][h + 8] = min(Dp[i][j | (1 << h)][h + 8], Dp[i][j][k + 8] + (i + k ? T[i + k] ^ T[i + h] : 0)); 34 } 35 } 36 } 37 int Ans(INF); 38 for (int k = 0; k < 9; ++k) Ans = min(Ans, Dp[N + 1][0][k]); 39 printf("%d\n", Ans); 40 } 41 }
标签:span open ide break view mes sizeof f11 else
原文地址:https://www.cnblogs.com/BlogOfASBOIER/p/12061039.html