Advertisement
Shiam7777777

Untitled

Mar 31st, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  4. #define ll long long
  5. #define ld double
  6. #define llu long long unsigned
  7.  
  8. #define inf 1 << 28
  9.  
  10. vector < vector < int > > mat(20);
  11.  
  12. int check[3];
  13.  
  14. int dp[3][20];
  15. int r = 3, c = 3;
  16. int call(int i, int j)
  17. {
  18.     if (i >= 0 && i < r and j >= 0 and j < c)
  19.     {
  20.         if (dp[i][j] != -1)
  21.             return dp[i][j];
  22.         int ret = inf;
  23.  
  24.         ret = min(ret, call(i + 1, 0) + mat[i][j]);
  25.         ret = min(ret, call(i + 1, 1) + mat[i][j]);
  26.         ret = min(ret, call(i + 1, 2) + mat[i][j]);
  27.         return dp[i][j] = ret;
  28.     }
  29.     else
  30.         return inf;
  31. }
  32.  
  33. int main()
  34. {
  35.     fast;
  36.     int t;
  37.     cin>>t;
  38.     for( int i = 1 ; i <= t ; i++ )
  39.     {
  40.         memset(dp, -1 , sizeof( dp ));
  41.         cout<<"Case "<<i<<": ";
  42.         cin>>r;
  43.         for( int q = 0 ; q < r ; q++ )
  44.         {
  45.             int r1 , g , b;
  46.             cin>>r1>>g>>b;
  47.             mat[q].push_back(r1);
  48.             mat[q].push_back(g);
  49.             mat[q].push_back(b);
  50.         }
  51.         for( int q = 0 ; q < r ; q++ )
  52.         {
  53.             for( int l = 0 ; l < 3 ; l++ )
  54.                 cout<<mat[q][l]<<" ";
  55.             cout<<endl;
  56.         }
  57.  
  58.         cout<<call( 0 , 0 )<<endl;
  59.     }
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement