原题传送门 #include <bits/stdc++.h> using namespace std; struct man { int tim; int mon; }; int n, M, T; man in[210]; int f[210][210][210];//step,m,t int dfs(int step, int t_left, int m_left) { if (t_left < 0 || m_left < 0) { return -1; } if (f[step][t_left][m_left] != -1) { return f[step][t_left][m_left]; } if (step == n) { return 0; } return f[step][t_left][m_left] = max(dfs(step + 1, t_left - in[step + 1].tim, m_left - in[step + 1].mon) + 1, dfs(step + 1, t_left, m_left)); } int main() { cin >> n >> M >> T; for (int i = 1; i <= n; i++) { cin >> in[i].tim >> in[i].mon; } memset(f, -1, sizeof(f)); cout << dfs(0, M, T) << endl; return 0; }