除了第一个点全wa
查看原帖
除了第一个点全wa
426120
limleep楼主2020/12/21 15:33
#include<stdio.h>
int maxx(int x, int y)
{
	if (x >= y)
		return x;
	else return y;
}
int main()
{
	int t, m;
	int bp[110][110]={0,}
	scanf("%d %d", &t, &m);
	int plant_space[110];
	int plant_value[110];
	for (int i = 1; i <= m; i++)
	{
		scanf("%d %d", &plant_space[i], &plant_value[i]);
	}
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= t; j++)
		{
			if (j >= plant_space[i])
				bp[i][j] = maxx(bp[i - 1][j], plant_value[i] + bp[i - 1][j - plant_space[i]]);
			else bp[i][j] = bp[i - 1][j];
		}
	}
	printf("%d", bp[m][t]);
	return 0;
}

大佬们帮dp初学者看看问题在哪里吧,除了第一个点全wa

2020/12/21 15:33
加载中...