Advertisement
mickypinata

CUBE-T104: Tasty Chocolate

Aug 6th, 2021
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1000;
  5.  
  6. int arr[N + 1], dp[N + 2][3001];
  7.  
  8. int main(){
  9.  
  10.     int nArr;
  11.     scanf("%d", &nArr);
  12.     for(int i = 1; i <= nArr; ++i){
  13.         scanf("%d", &arr[i]);
  14.     }
  15.     for(int i = 1; i <= nArr; ++i){
  16.         dp[i][3000] = 1e9;
  17.     }
  18.     for(int i = nArr; i >= 1; --i){
  19.         for(int x = 2999; x >= 0; --x){
  20.             int ans = 1e9;
  21.             if(arr[i] > x){
  22.                 ans = dp[i + 1][arr[i]];
  23.             }
  24.             dp[i][x] = min(ans, 1 + dp[i + 1][x + 1]);
  25.         }
  26.     }
  27.     cout << dp[1][0];
  28.  
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement