Advertisement
Saleh127

Light oj(LO) 1047

Apr 27th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. test
  12. {
  13.  
  14. ll n,m,i,j,k,l=1e9;
  15.  
  16. cin>>n;
  17.  
  18. ll dp[100][3]={0};
  19.  
  20. ll a[n+2],b[n+2],c[n+2];
  21.  
  22. for(i=0; i<n; i++)
  23. {
  24. cin>>a[i]>>b[i]>>c[i];
  25. }
  26.  
  27. dp[0][0]=a[0];
  28. dp[0][1]=b[0];
  29. dp[0][2]=c[0];
  30.  
  31. for(i=1; i<n; i++)
  32. {
  33. dp[i][0]=min(dp[i-1][1],dp[i-1][2])+a[i];
  34. dp[i][1]=min(dp[i-1][0],dp[i-1][2])+b[i];
  35. dp[i][2]=min(dp[i-1][1],dp[i-1][0])+c[i];
  36. }
  37.  
  38.  
  39. l=min(dp[n-1][0],min(dp[n-1][1],dp[n-1][2]));
  40.  
  41. cout<<"Case "<<cs<<": "<<l<<endl;
  42. }
  43.  
  44.  
  45. return 0;
  46. }
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement