欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > 1022. 宠物小精灵之收服

1022. 宠物小精灵之收服

2024/10/23 3:05:51 来源:https://blog.csdn.net/2301_81278039/article/details/143001224  浏览:    关键词:1022. 宠物小精灵之收服

思路

双层dp

代码

#include <bits/stdc++.h>
using namespace std;const int N = 1010, mod = 1e9 + 7;int n, m, k, x, y, z, ans, t;
int w[N], f[N][N];void solve()
{cin >> n >> m >> k;for (int i = 1; i <= k; i ++ ){cin >> x >> y;for (int j = n; j >= x; j -- ){for (int l = m - 1; l >= y; l -- ){f[j][l] = max(f[j][l], f[j - x][l - y] + 1);}}}cout << f[n][m - 1] << " ";ans = m - 1;while (ans > 0 && f[n][ans - 1] == f[n][m - 1]) ans --;cout << m - ans << "\n";
}signed main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T = 1;
//	cin >> T;while (T -- ){solve();}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com