トピック:
シーケンスを与える、間隔* kを許可する、または乗算できない、間隔と最大を許可する
アイデア:
動的プログラミング
dp [1]は、現在のノードが現在のノードの更新間隔の前であることを示します。
dp [2]は、現在のノードが更新間隔内であることを示します。
dp [3]は、現在のノードが更新間隔の後であることを示します
1 #include <cstdio> 2 #include < string .h> 3 #include <algorithm> 4 #include <cmath> 5 #include <iostream> 6 #include <vector> 7 #include <queue> 8 #include < set > 9 #include <map> 10 #include <cctype> 11 #define ios ios :: sync_with_stdio(false)、cin.tie(0)、cout.tie(0) 12 #define mem(a、x)memset(a、 x、sizeof(a)) 13 #define lson rt << 1、l、mid 14 #define rson rt << 1 | 1、mid + 1、 r 15 #define P pair <int、int> 16 #define ull unsigned long long 17 using namespace std; 18 typedef long long ll; 19 const int maxn = 1e6 + 10 ; 20 const ll mod = 998244353 ; 21 const int inf = 0x3f3f3f3f ; 22 const long long INF = 0x3f3f3f3f3f3f3f3f ; 23 const double eps = 1e- 7 ; 24 インラインll read() 25 { 26 ll X = 0、w = 0 ; char ch = 0 ; 27 while(!isdigit(ch)){w | = ch == ' - ' ; ch = getchar(); } 28 while(isdigit(ch))X =(X << 3)+(X << 1)+(ch ^ 48)、ch = getchar(); 29 リターン w?- X:X; 30 } 31 ll n、m; 32 ll dp [ 10 ]; 33 int main() 34 { 35 n = read()、m = read(); 36 ll ans = 0 ; 37 for(int i = 1 ; i <= n; ++ i) 38 { 39 ll num = read(); 40 dp [ 1 ] = max(0 * 1ll、dp [ 1 ] + num); 41 dp [ 2 ] = max(dp [ 1 ]、dp [ 2 ] + num * m); 42 dp [ 3 ] = max(dp [ 2 ]、dp [ 3] + num); 43 ans = max(ans、dp [ 3 ]); 44 } 45 cout << ans << endl; 46 return 0 ; 47 }