The Preliminary Contest for ICPC Asia Shenyang 2019

C. Dawn-K's water (完全背包)

 

 

样例输入

3 3
2 1
3 1
1 1
3 5
2 3
1 2
3 3

样例输出

3 3
3 6

题意分析:

不同的水有不同的价格,要求买到至少m千克的水,输出花的最少的钱和实际买到的水的重量。

解题思路:

题目和完全背包差不多,主要有两个难点:可以买超过m的水,需要求实际买到的水的重量。

用dpv[i]表示买重量为i的水需要的最少的钱,

用dpw[i]表示买重量为i的水实际买到的水的重量,这个地方需要好好理解一下,如果我买i+x的水花的钱要低于买i的水的钱,我可以直接买i+x重量的水。

下面就是相当于完全背包,当 j-a[i].w < 0 时,也就是第i瓶水的重量大于所需要的重量 j 的时候,比较一下价格的大小,如果a[i].v更小, 那么我可以用更少的钱买到更多的水,所以可以更新dpv[j]和dpw[j]。

j-a[i].w >= 0 的时候就是完全背包了。

另外,当两个价格相同的时候取水的重量更大的一个,这是两个里面都有的一个更新dpw[j]的一个判断。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 1e4+20;
struct date {
	int w;
	int v;
}a[N];
int dpv[N], dpw[N];
int main()
{
	int n, m;
	while(scanf("%d%d", &n, &m)!=EOF) {
		for(int i=0; i<n; i++)
			scanf("%d%d", &a[i].v, &a[i].w);
		memset(dpv, 0x3f, sizeof(dpv));
		memset(dpw, 0, sizeof(dpw));
		dpv[0]=0;
		for(int i=0; i<n; i++) {
			for(int j=1; j<=m; j++) {
				if(j-a[i].w < 0) {
					if(dpv[j] == a[i].v)
						dpw[j] = max(dpw[j], a[i].w);
					else if(dpv[j] > a[i].v) {
						dpv[j] = a[i].v;
						dpw[j] = a[i].w;
					}
				}
				else {
					if(dpv[j] == dpv[j-a[i].w] + a[i].v)
						dpw[j] = max(dpw[j], dpw[j-a[i].w] + a[i].w);
					else if(dpv[j] > dpv[j-a[i].w] + a[i].v) {
						dpv[j] = dpv[j-a[i].w] + a[i].v;
						dpw[j] = dpw[j-a[i].w] + a[i].w;
					}
				}
			}
		}
		printf("%d %d\n", dpv[m], dpw[m]);	
	}
	return 0;
} 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Sure, I'd be happy to give you some ideas for organizing a speech contest. Here are some suggestions: 1. Determine the theme and rules: Decide on the theme of the contest and the rules for participants. Will it be an open topic, or will there be a specific theme? What is the maximum length of the speech? Will there be any specific guidelines for language or content? 2. Decide on the judging criteria: Determine how the speeches will be evaluated. Will judges be looking for content, delivery, or both? Will there be a score sheet or rubric that judges will use to score the speeches? 3. Recruit judges: Find people who are qualified to judge the speeches. Ideally, they should have experience in public speaking or have a background in the theme of the contest. 4. Promote the contest: Advertise the contest to potential participants, such as students, professionals, or members of a specific community. Use social media, flyers, and other methods to get the word out. 5. Registration and selection: Set a deadline for registration and selection of participants. Consider having a preliminary round to narrow down the field before the final competition. 6. Prepare the venue: Ensure that the venue is suitable for the contest. Make sure that there is adequate seating, sound equipment, and lighting for the speakers. 7. Hold the contest: Set a date and time for the contest, and make sure that all participants and judges are aware of the schedule. Encourage audience participation and provide refreshments. 8. Award ceremony: After the contest, hold an award ceremony to recognize the winners and participants. Provide certificates or other prizes to the top performers. I hope these ideas help you in organizing a successful speech contest!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张宜强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值