AOJ2903. USACO 3.1.2 Score Inflation (完全背包)
2019-07-24 15:48
323 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/jal517486222/article/details/97135749
USACO 3.1.2 Score Inflation (完全背包)
一、题目大意
题目传送门:USACO 3.1.2 Score Inflation
二、解题思路
这是个典型的完全背包,就是不限定物品数量,求最大价值。
刚开始用贪心写的,居然过了11/12的数据,可怕,最后一组过不了,换成了dp才过了全部数据。我以为根据比重排序就行了,但想想感觉好像有点问题,幸好最后一组数据让我WA掉了,要不然我就被带偏了
动归转移方程:
dp[i] = max(dp[i], dp[i-v[j].second]+v[j].first);
三、AC代码
#include <bits/stdc++.h> #define endl '\n' using namespace std; using ll =unsigned long long; template<typename T=int> inline T read() { T x; cin >> x; return x; } template<typename T=int> void OO(vector <T> v, string comm="") { cerr << comm << " : " << endl; for (auto i: v) { cerr << i << ' '; } cerr << endl; } typedef pair<int, int> pr; int main() { freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n = read(), k = read(); vector<pr>v(k); for(auto &i: v){ i.first = read(); i.second = read(); } vector<int>dp(n+1); for(int j = 0; j < k; j++){ for(int i = v[j].second; i <= n; i++){ dp[i] = max(dp[i], dp[i-v[j].second]+v[j].first); } } cout << dp[n] << endl; return 0; }
相关文章推荐
- USACO Section 3.1 Score Inflation(完全背包)
- USACO-Section3.1 Score Inflation【完全背包】
- 【USACO 3.1】Score Inflation(完全背包)
- USACO 3.1 Score Inflation (完全背包) P2722 总分 Score Inflation
- 1683 USACO 3.1 Score Inflation (完全背包)
- USACO 3.1 Score Inflation(完全背包 模版)
- USACO 3.1 Score Inflation (完全背包)
- 【完全背包】Score Inflation 总分
- Score Inflation 完全背包 注释部分是错误的解法
- USACO Section 3.1 Score Inflation(完全背包)
- [U]3.1.2 Score Inflation 赤裸裸的多重背包问题
- 背包问题 2 完全背包解题报告
- poj 2063 完全背包
- HDU 1248 寒冰王座 完全背包
- HDU ACM 2844 Coins (多重背包)----------------01背包,完全背包,多重背包模板
- 完全背包——方案个数 UVA11137 Ingenuous Cubrency
- 包子凑数(数论+完全背包)
- 湫湫系列故事——减肥记I(杭电4508)(完全背包)
- NYOJ 311 完全背包
- NYOJ 311 完全背包(完全背包)