SDUT ACM 2408 Pick apples 贪心+完全背包
2013-04-20 18:07
281 查看
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 kind 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 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.示例输入
1 1 1 2 1 3 1 6
示例输出
Case 1: 6
来源
2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛#include<stdio.h> #include<string.h> #include<algorithm> long long dp[1110]; int main() { int t, sum; long long s[5], p[5]; //这里必须用long long,不知道原因。。。 double val, max; scanf("%d", &t); for(int k = 1; k <= t; k++) { int x = 0; double val, max = 0; memset(dp, 0, sizeof(dp)); for(int i = 0; i < 3; i++) { scanf("%lld %lld", &s[i], &p[i]); val = 1.0 * p[i] / s[i]; if(val > max) { max = val; x = i; //记录性价比最高的苹果的下标 } } scanf("%d", &sum); //背包总容量 if(sum <= 1000) //1000以下用完全背包,超出就贪心加背包 { for(int i = 0; i < 3; i++) for(int v = s[i]; v <= sum; v++) dp[v] = std::max(dp[v], dp[v-s[i]]+p[i]); printf("Case %d: %lld\n", k, dp[sum]); } else { int lem = sum - 1000; //用于贪心的背包容量 int n = lem / s[x]; //能装的性价比最高的苹果的数量 long long w = n * p[x]; //贪心所得的利润 int cur = sum - n * s[x]; //剩余的背包容量,剩余的用完全背包 for(int i = 0; i < 3; i++) for(int v = s[i]; v <= cur; v++) dp[v] = std::max(dp[v], dp[v-s[i]]+p[i]); printf("Case %d: %lld\n", k, dp[cur] + w); } } return 0; }
相关文章推荐
- SDUT 2408 Pick apples 贪心+背包(大容量背包)
- sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛
- sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
- Pick apples sdut 2408 (V 超大的背包)
- SDUT:2408 Pick apples(贪心+完全背包)
- SDUT2408 Pick apples(贪心+完全背包)
- SDUT 2408 Pick apples(完全背包+贪心)2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛
- sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛
- [2012山东ACM省赛] Pick apples (贪心,全然背包,枚举)
- Pick apples(大范围贪心,小范围完全背包)
- HDUT-2408-Pick apples(贪心+背包)
- poj 2063 Investment 贪心+完全背包
- *HDU 5305 - Delicious Apples (贪心+背包)
- UVA 10465 - Homer Simpson 贪心或完全背包
- 完全背包问题(贪心)
- HDU - 1248 - 寒冰王座 (完全背包 or 贪心)
- uva 10465 - Homer Simpson(贪心+完全背包)