- //#include<iostream>
- //#include<vector>
- //#include<algorithm>
- //#include<utility>
- #include<bits/stdc++.h>
- using namespace std;
- int Solve(int R, int C, const vector<vector<int>> &values, vector<vector<int>> &dp)
- {
- if(dp[R][C]!=-1)return dp[R][C];
- int ans = 0;
- for(int i=1;i<R;++i)
- {
- ans = max( Solve(i,C,values,dp)+Solve(R-i,C,values,dp), ans);
- }
- for(int i=1;i<C;++i)
- {
- ans = max( Solve(R,i,values,dp)+Solve(R,C-i,values, dp), ans);
- }
- if(values[R][C]!=0)ans = max(ans,values[R][C]);
- dp[R][C] = ans;
- return ans;
- }
- int main()
- {
- int R, C;
- cin >> R >> C;
- int N;
- cin >> N;
- vector<vector<int>> values(201, vector<int>(201, 0));
- vector<vector<int>> dp_table(R+1, vector<int>(C+1, -1));
- for(int i=0; i<N; ++i)
- {
- int V, a, b;
- cin >> V >> a >> b;
- values[a][b] = max(values[a][b], V);
- values[b][a] = max(values[b][a], V);
- }
- cout << Solve(R, C, values, dp_table);
- return 0;
- }
- /*
- 6 6
- 1
- 5 1 1
- 3 5
- 4
- 10 2 2
- 2 3 1
- 5 3 4
- 1 3 1
- 详解vector二维数组的全部操作(超细图例解析!!!)
- */
複製代碼 |