Advertisement
Zeinab_Hamdy

Untitled

Mar 22nd, 2024
874
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define nl "\n"
  4. #define fi first
  5. #define se second
  6. #define pb push_back
  7. #define ll long long
  8. #define ull unsigned ll
  9. #define RV  return void
  10. #define sz(x) int(x.size())
  11. #define all(v) v.begin(), v.end()
  12. #define rall(v) v.rbegin(), v.rend()
  13. #define fixed(n) fixed << setprecision(n)
  14. #define cin(v) for (auto&i:v) cin >> i;
  15. #define cout(v) for (auto&i:v) cout << i << " ";
  16. #define clr(memo, x) memset(memo, x, sizeof memo)
  17. #define FastCode ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  18.  
  19. void  Zainab(){
  20.             // #ifndef ONLINE_JUDGE
  21.               freopen("hobz.in", "r", stdin);
  22.               // freopen("longpath.out", "w", stdout);
  23.             // #endif
  24. }
  25.  
  26.  
  27. ll n;
  28. vector < ll > v ,dp;
  29.  
  30. const ll inf = 1e15;
  31.  
  32. ll rec(ll idx ) {
  33.    
  34.     if(idx >= n) return (idx == n ? 0 : inf);
  35.    
  36.     ll & ret = dp[idx];
  37.     if(~ret)
  38.         return ret ;
  39.     ret =inf;
  40.    
  41.     for(ll i =1 ; i <= min( 7ll , n-idx ) ; ++i){
  42.  
  43.         ret = min(ret , 1ll * v[idx] * i  + rec(idx+i));
  44.     }
  45.  
  46.     return ret;
  47. }
  48.  
  49. void myCode( int test){
  50.  
  51. cin >> n;
  52. v.assign(n,0);
  53. cin(v);
  54.  
  55. dp.assign(n+1 , -1);
  56.  
  57. cout << rec(0) << nl;
  58. // for(int i =0 ; i < n ; i++) cout << i << " " << dp[i] << nl;
  59.  
  60. }
  61.  
  62.  
  63. int main(){
  64.                                    FastCode ;
  65.  
  66.     int testCase=1;
  67.         //  cin >> testCase ;
  68.       for(int i=1 ; i<= testCase ; i++)
  69.         myCode(i);
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement