标签:背包问题
1.题目描述:点击打开链接
2.解题思路:本题是无限背包问题,根据重量的约束关系,直接暴力搜索。
3.代码:
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<sstream> #include<set> #include<vector> #include<stack> #include<map> #include<queue> #include<deque> #include<cstdlib> #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<functional> using namespace std; typedef long long ll; ll C, hr, wr, hb, wb; int main() { //freopen("t.txt", "r", stdin); while (cin >> C >> hr >> hb >> wr >> wb) { ll ans = 0; for (ll i = 0; i < 100000; i++) { if (i*wr <= C) ans = max(ans, i*hr + (C - wr*i) / wb*hb); if (i*wb <= C) ans = max(ans, i*hb + (C - wb*i) / wr*hr); } cout << ans << endl; } return 0; }
ZeptoLab Code Rush 2015 C. Om Nom and Candies
标签:背包问题
原文地址:http://blog.csdn.net/u014800748/article/details/44887267