提交时间:2023-12-18 13:32:19
运行 ID: 116700
# include <iostream> using namespace std ; int rm [114514] , maxs = 0 , n ; bool flg [114514] ; void dfs ( int cur , int sum ) { if ( cur == n + 1 ) { maxs = max ( maxs , sum ) ; return ; } else if ( flg [cur - 1] == true || ( cur == n && flg [1] == true ) ) { dfs ( cur + 1 , sum ) ; } else { flg [cur] = true ; dfs ( cur + 1 , sum + rm [cur] ) ; flg [cur] = false ; dfs ( cur + 1 , sum ) ; } return ; } int main ( ) { cin >> n ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> rm [i] ; } flg [0] = false ; dfs ( 1 , 0 ) ; cout << maxs << endl ; return 0 ; }