在一道站外题中
这种写法:
dp[p][0]=max(max(dp[p-1][2]+b[i][0][0],dp[p-1][1]+b[i][1][0]),dp[p-1][0]+b[i][2][0]);
dp[p][1]=max(max(dp[p-1][2]+b[i][0][1],dp[p-1][1]+b[i][1][1]),dp[p-1][0]+b[i][2][1]);
dp[p][2]=max(max(dp[p-1][2]+b[i][0][2],dp[p-1][1]+b[i][1][2]),dp[p-1][0]+b[i][2][2]);
比这种写法(在题目中等价)
for(int t=0;t<=2;t++){
dp[p][t]=0;
for(int x=0;x<=2;x++)
for(int y=0;y<=2-x;y++)
dp[p][t]=max(dp[p][t],dp[p-1][x]+b[i][y][t]);
}
快一倍(下面的写法会T)
这是为什么呢?