View Code of Problem 4041

#include<iostream>
#include<algorithm>
using namespace std;
typedef struct sz {
	int id;
	int num;
}sz;
//sz a[10001];
bool cmp(sz a, sz b)
{
	return a.num < b.num;
}
sz a[100001];
int max(int a, int b)
{
	if (a > b)
		return a;
	return b;
}
int main()
{
	int n, t;
	int value[301], time[301];
	int dp[301][301];
	cin >> n >> t;
	memset(dp, 0, sizeof(dp));
	for (int i = 0;i < n;i++)
	{
		cin >> time[i] >> value[i];
	}
	
	for(int j=1;j<=t;j++)
		if (t > time[0])
		{
			dp[0][j] = value[0];
		}
	int max1 = 0;
	int a1;
	for (int i = 1;i < n;i++)
	{
		for (int j = 1;j <= t;j++)
		{
			if (j - time[i] >= 0)
				a1 = value[i] + dp[i - 1][j - time[i]];
			else
				a1 = 0;
			int a2 = dp[i - 1][j];
			dp[i][j] = max(a1, a2);
			if (dp[i][j] > max1)
				max1 = dp[i][j];
		}
	}
	cout << max1;
}
/*
Main.cc: In function 'int main()':
Main.cc:26:2: error: 'memset' was not declared in this scope
  memset(dp, 0, sizeof(dp));
  ^~~~~~
Main.cc:26:2: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
Main.cc:3:1:
+#include <cstring>
 using namespace std;
Main.cc:26:2:
  memset(dp, 0, sizeof(dp));
  ^~~~~~
*/

Double click to view unformatted code.


Back to problem 4041