@@ -14,6 +14,17 @@ int main(){
14
14
// there are three groups of relations here: 1-2,2-3,3-4
15
15
/*
16
16
the first sub-array is dontGoWell[i],
17
+
18
+ dontGoWell[i][j][k]: i for which group you want to use, it's either 1-2, or 2-3 or 3-4
19
+ j for the number of dish from 2,3,4 that doesn't go well with k from 1,2,3, respectively.
20
+ k for the number of dish from 1,2,3 that doesn't go well with j from 2,3,4, respectively.
21
+ So, if I want to find out which dish from course 1 doesn't go well with dish from course 2, then i would be 0. Similarly, i==1 if 2-3, i==2 if 3-4
22
+ Then, determine the value of j, which records the number of dish from course 2,3 and 4. That means if dish 5 from course 2 goes well with all dishes
23
+ from 1, then dontGoWell[i][5].size()==0. Otherwise, there will be elements that are not compatible with dish 5 from course 2.
24
+ It's a graph. There are 3 graphs in this case.
25
+ Graph 1: 1-2
26
+ Graph 2: 2-3
27
+ Graph 3: 3-4
17
28
*/
18
29
vector<vector<vector<int >>> dontGoWell (3 );
19
30
for (int i=0 ;i<3 ;i++){
@@ -37,4 +48,35 @@ int main(){
37
48
dontGoWell[i][y].push_back (x);
38
49
}
39
50
}
51
+ /*
52
+ dp[i][j]: i would be the course number, i==0 means for first course, i==1 means second course and so on
53
+ j would be the cost for each type of dish from course i
54
+ */
55
+ vector<vector<int >> dp (4 );
56
+ /*
57
+ Initially, for the first course,the cost would be the same as the original cost of each type of dish from course 1.
58
+ For dp[0+1], which stands for course 2, there are p=typesOfFourseCourses[0+1] cost obviously, namely there are p elements in vector dp[1].
59
+ We can store p elements int dp[1]. So we resize it to make it fit for storing all elements of cost from course 2.
60
+ */
61
+ dp[0 ]=costOfEachTypeOfDish[0 ];
62
+ for (int i=0 ;i<3 ;i++){
63
+
64
+ dp[i+1 ].resize (typesOfFourCourses[i+1 ]);
65
+ // could be used for storing elements with the same value
66
+ multiset<int > s;
67
+ for (int j=0 ;j<typesOfFourCourses[i];j++){
68
+ /*
69
+ i==0, the number of types of dishes from course 1
70
+ */
71
+ s.insert (dp[i][j]);
72
+ }
73
+ for (int j=0 ;j<typesOfFourCourse[i+1 ];j++){
74
+ for (auto k: dontGoWell[i][j]){
75
+ s.erase (s.find (dp[i][k]));
76
+ }
77
+ if (s.empty ()){
78
+ dp[i+1 ][j]=int (4e8 +43 );
79
+ }else
80
+ }
81
+ }
40
82
}
0 commit comments