思路:
dp[i][0]表示第i家店铺不行窃,dp[i][1]表示第i家店铺行窃,然后从两种状态中转移即可
代码语言:javascript复制#include<bits/stdc .h>
using namespace std;
const int N=1e5 10;
int t,a[N],n,dp[N][2];
int main(){
cin>>t;
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i )scanf("%d",&a[i]);
for(int i=1;i<=n;i ){
dp[i][1]=dp[i-1][0] a[i];
dp[i][0]=max(dp[i-1][1],dp[i-1][0]);
}
cout<<*max_element(dp[n],dp[n] 2)<<endl;
}
}