Advertisement
SuitNdtie

macrosoft doors

May 29th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include<stdio.h>
  2. typedef long long int ll;
  3.  
  4. int n;
  5. int const N = 100010;
  6. ll const inf = 1e18;
  7. ll A[3][N];
  8.  
  9. ll min(ll a , ll b){
  10.     return a < b ? a : b;
  11. }
  12.  
  13. ll dp[3][N];
  14.  
  15. ll cal(int level,int I){
  16.     if(I > n)return 0;
  17.     if(dp[level][I] != -1)return dp[level][I];
  18.    
  19.     if(level == 2)return dp[level][I] =  cal(level , I + 1) + A[level][I];
  20.     ll ans = min(cal(level,I+1),cal(level+1,I+1)) + A[level][I];
  21.    
  22. //  printf("Test (%d,%d) : %lld\n",level,I,ans);
  23.     return dp[level][I] = ans;
  24. }
  25.  
  26. int main()
  27. {
  28.     for(int i = 0 ; i < 3 ; i ++)for(int j = 0 ; j < N ; j ++)dp[i][j] = -1;
  29.     scanf("%d",&n);
  30.     for(int j = 0 ; j < 3 ; j ++)for(int i = 1 ; i <= n ; i ++)scanf("%lld",&A[j][i]);
  31.     if(true){ //dia bound
  32.         A[1][1] = inf;
  33.         A[2][1] = inf;
  34.         A[2][2] = inf;
  35.         A[0][n] = inf;
  36.         A[0][n-1] = inf;
  37.         A[1][n] = inf; }
  38.        
  39.     printf("%lld",cal(0,1));
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement