Submission #1113184

#TimeUsernameProblemLanguageResultExecution timeMemory
1113184minhvuleFeast (NOI19_feast)C++17
41 / 100
42 ms61000 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define freo(task) if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i ++) #define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; i --) #define bit(x, i) ((x >> i) & 1) #define oo 1e18 #define all(v) v.begin(), v.end() using ll = long long; using pii = pair<int, int>; using vi = vector<int>; // mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); // ll rand(ll l, ll r) { assert(l <= r); return uniform_int_distribution<ll>(l, r)(rd); } const int N = 1e5 + 5; const int mod = 1e9 + 7; const int base = 31; int n, k, a[N], dp[N]; /* dp[i][j] là tổng lớn nhất khi chia i món cho j thằng sub5: dp O(n ^ 3) dp[i][j] = max(dp[i - 1][j], max(dp[k - 1][j]) + (a[k] -> i) sub6: O(n ^ 2) for(j 1->k) dp_divide() sub7: dp alien trick O(nlog(n)) */ int dp1[305][305]; void sub5(){ FOR(i, 1, n) cin>>a[i], a[i] += a[i - 1]; FOR(i, 1, n) FOR(j, 1, k){ dp1[i][j] = dp1[i - 1][j]; FOR(t, 1, i - 1) dp1[i][j] = max(dp1[i][j], dp1[t - 1][j - 1] + a[i] - a[t - 1]); } // FOR(i, 1, n) cout<<dp1[i][k]<<" "; cout<<dp1[n][k]; } int dp2[2005][2005], g[2005][2005]; void sub6(){ FOR(i, 1, n) cin>>a[i]; FOR(i, 1, n) FOR(j, 1, k){ dp2[i][j] = dp2[i - 1][j] + a[i]; dp2[i][j] = max(dp2[i][j], g[i - 1][j - 1] + a[i]); g[i][j] = max(g[i - 1][j], dp2[i][j]); } int ans = 0; FOR(j, 1, k) ans = max(ans, g[n][j]); cout<<ans; } void solve(){ cin>>n>>k; sub6(); } int32_t main(){ ios::sync_with_stdio(false); cin.tie(NULL); // freo(""); int nTest = 1; // cin>>nTest; while(nTest --) solve(); // cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...