Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- typedef long long int ll;
- int n;
- int const N = 100010;
- ll const inf = 1e18;
- ll A[3][N];
- ll min(ll a , ll b){
- return a < b ? a : b;
- }
- ll dp[3][N];
- ll cal(int level,int I){
- if(I > n)return 0;
- if(dp[level][I] != -1)return dp[level][I];
- if(level == 2)return dp[level][I] = cal(level , I + 1) + A[level][I];
- ll ans = min(cal(level,I+1),cal(level+1,I+1)) + A[level][I];
- // printf("Test (%d,%d) : %lld\n",level,I,ans);
- return dp[level][I] = ans;
- }
- int main()
- {
- for(int i = 0 ; i < 3 ; i ++)for(int j = 0 ; j < N ; j ++)dp[i][j] = -1;
- scanf("%d",&n);
- for(int j = 0 ; j < 3 ; j ++)for(int i = 1 ; i <= n ; i ++)scanf("%lld",&A[j][i]);
- if(true){ //dia bound
- A[1][1] = inf;
- A[2][1] = inf;
- A[2][2] = inf;
- A[0][n] = inf;
- A[0][n-1] = inf;
- A[1][n] = inf; }
- printf("%lld",cal(0,1));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement