Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
116141 | 梁乃元 | 打家劫舍 | C++ | 通过 | 100 | 0 MS | 248 KB | 584 | 2023-12-16 08:43:43 |
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 ; } if ( flg [cur - 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 ; }
exit code: 0, checker exit code: 0
exit code: 0, checker exit code: 0
exit code: 0, checker exit code: 0
exit code: 0, checker exit code: 0