Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- #define ll long long
- #define ld double
- #define llu long long unsigned
- #define inf 1 << 28
- vector < vector < int > > mat(20);
- int check[3];
- int dp[3][20];
- int r = 3, c = 3;
- int call(int i, int j)
- {
- if (i >= 0 && i < r and j >= 0 and j < c)
- {
- if (dp[i][j] != -1)
- return dp[i][j];
- int ret = inf;
- ret = min(ret, call(i + 1, 0) + mat[i][j]);
- ret = min(ret, call(i + 1, 1) + mat[i][j]);
- ret = min(ret, call(i + 1, 2) + mat[i][j]);
- return dp[i][j] = ret;
- }
- else
- return inf;
- }
- int main()
- {
- fast;
- int t;
- cin>>t;
- for( int i = 1 ; i <= t ; i++ )
- {
- memset(dp, -1 , sizeof( dp ));
- cout<<"Case "<<i<<": ";
- cin>>r;
- for( int q = 0 ; q < r ; q++ )
- {
- int r1 , g , b;
- cin>>r1>>g>>b;
- mat[q].push_back(r1);
- mat[q].push_back(g);
- mat[q].push_back(b);
- }
- for( int q = 0 ; q < r ; q++ )
- {
- for( int l = 0 ; l < 3 ; l++ )
- cout<<mat[q][l]<<" ";
- cout<<endl;
- }
- cout<<call( 0 , 0 )<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement