题解 | #删除相邻数字的最大分数#
删除相邻数字的最大分数
https://www.nowcoder.com/practice/3bcf72c738b6494bbe1ebe0ffde56152
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int x[10001] = {0},y[10001] = {0};
int arr[10001] = { 0 };
for (int i = 0; i < n; i++) {
int x = 0;
cin >> x;
arr[x] += x;
}
for(int j=1;j<10001;j++)
{
x[j] = arr[j] + y[j-1];
y[j] = max(x[j-1],y[j-1]);
}
cout<<(x[10000]>y[10000] ? x[10000] : y[10000])<<endl;
return 0;
}
查看29道真题和解析