Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int dp[25][10][10];
- int main()
- {
- int n;
- cin>>n;
- int m[n][3];
- for(int i=0; i<n; i++){
- for(int j=0; j<3; j++){
- cin>>m[i][j];
- }
- }
- for(int i=0; i<=n; i++){
- for(int j=0; j<3; j++){
- for(int z= 0; z < 3; z++) {
- dp[i][j][z]=2e9;
- }
- }
- }
- dp[0][0][0]=m[0][0];
- dp[0][1][1]=m[0][1];
- dp[0][2][2]=m[0][2];
- for(int i = 1; i < n; i++) {
- for(int j = 0; j < 3; j++) {
- dp[i][0][j] = min(dp[i - 1][1][j], dp[i - 1][2][j]) + m[i][0];
- dp[i][1][j] = min(dp[i - 1][0][j], dp[i - 1][2][j]) + m[i][1];
- dp[i][2][j] = min(dp[i - 1][0][j], dp[i - 1][1][j]) + m[i][2];
- }
- }
- int result = 2e9;
- for(int i = 0; i < 3; i++) {
- for(int j = 0; j < 3; j++ ){
- if(i != j) {
- result = min(result, dp[n - 1][i][j]);
- }
- }
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement