第三届ACM山东省赛 Pick apples [贪心+动规]
2015-04-12 21:42
225 查看
超大背包问题,刚开始想复杂了。分段填充背包,前面一大部分用性价比最高的填充,最后一部分动规就可以了。
题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2408
Time Limit: 1000ms Memory limit: 165536K 有疑问?点这里^_^
of apple has a size and a price to be sold. Now the little girl wants to gain more profits, but she does not know how. So she asks you for help, and tell she the most profits she can gain.
In each case, there are four lines. In the first three lines, there are two integers S and P in each line, which indicates the size (1 <= S<= 100) and the price (1 <= P <= 10000) of this kind of apple.
In the fourth line there is an integer V,(1 <= V <= 100,000,000)indicates the volume of the girl's bag.
题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2408
Pick apples
Time Limit: 1000ms Memory limit: 165536K 有疑问?点这里^_^
题目描述
Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because she has never seen so many apples before. Each kindof apple has a size and a price to be sold. Now the little girl wants to gain more profits, but she does not know how. So she asks you for help, and tell she the most profits she can gain.
输入
In the first line there is an integer T (T <= 50), indicates the number of test cases.In each case, there are four lines. In the first three lines, there are two integers S and P in each line, which indicates the size (1 <= S<= 100) and the price (1 <= P <= 10000) of this kind of apple.
In the fourth line there is an integer V,(1 <= V <= 100,000,000)indicates the volume of the girl's bag.
输出
For each case, first output the case number then follow the most profits she can gain.示例输入
11 12 13 16
示例输出
Case 1: 6
#include "iostream" #include "cstdio" #include "cstring" #include "cstdlib" #include "algorithm" typedef long long LL; using namespace std; LL dp[10240]; struct Node{ LL sz, pri; double rat; bool operator < (const Node & rhs) const { return rat < rhs.rat; } }; int main(int argc, char const *argv[]) { LL T, kase = 0; cin >> T; while(T--){ Node v[3]; for(LL i = 0; i < 3; ++i){ cin >> v[i].sz >> v[i].pri; v[i].rat = v[i].sz * 1.0 / v[i].pri; } sort(v, v + 3); memset(dp, 0, sizeof(dp)); LL all; cin >> all; if(all < 10000){ for(LL i = 1; i <= all; ++i) for(LL j = 0; j < 3; ++j) if(i - v[j].sz >= 0) dp[i] = max(dp[i], dp[i-v[j].sz] + v[j].pri); printf("Case %lld: %lld\n", ++kase, dp[all]); } else{ LL cnt = (all - 10000) / v[0].sz; all -= cnt * v[0].sz; for(LL i = 1; i <= all; ++i) for(LL j = 0; j < 3; ++j) if(i - v[j].sz >= 0) dp[i] = max(dp[i], dp[i-v[j].sz] + v[j].pri); printf("Case %lld: %lld\n", ++kase, dp[all] + cnt * v[0].pri); } } return 0; }
相关文章推荐
- 第三届ACM山东省赛 Pick apples [贪心+动规]
- SDUT 2408 Pick apples(完全背包+贪心)2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛
- 山东省第三届ACM省赛 Pick apples
- Pick apples(山东省第三届ACM大学生程序设计竞赛)
- 2013山东省第三届ACM省赛 Pick apples
- Pick apples(山东省第三届ACM程序设计大赛 贪心+背包)
- 第三届ACM山东省赛D题_Mine Number_枚举
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛——Fruit Ninja II
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
- 山东省第三届ACM省赛题——The Best Seat in ACM Contest(模拟)
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛 Fruit Ninja I
- SDUT 2410 Mine Number 2012年山东省第三届ACM大学生程序设计竞赛题
- 山东省第三届ACM大学生程序设计竞赛(待添加)
- Fruit Ninja II(山东省第三届ACM大学生程序设计竞赛 )
- [2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !
- Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛——Pixel density
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛:n a^o7 !
- Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)