QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#510994#3407. Gift HuntingPetroTarnavskyi#AC ✓401ms4004kbC++201.6kb2024-08-09 14:59:362024-08-09 14:59:37

Judging History

你现在查看的是最新测评结果

  • [2024-08-09 14:59:37]
  • 评测
  • 测评结果:AC
  • 用时:401ms
  • 内存:4004kb
  • [2024-08-09 14:59:36]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N1 = 504;
const int N2 = 54;
const int INF = 1e9 + 7;
int dp[N1][N2][2];
int ndp[N1][N2][2];
int v1, v2, n;

void updMax(int& a, int b)
{
	a = max(a, b);
}

void solve()
{
	FOR (i, 0, N1) FOR (j, 0, N2) dp[i][j][0] = dp[i][j][1] = -INF;
	dp[0][0][0] = 0;
	FOR (it, 0, n)
	{
		int p, h, s;
		cin >> p >> h >> s;
		FOR (i, 0, N1) FOR (j, 0, N2) ndp[i][j][0] = ndp[i][j][1] = -INF;
		FOR (i, 0, v1 + 1)
		{
			FOR (j, 0, v2 + 1)
			{
				FOR (t, 0, 2)
				{
					if (i + p <= v1)
						updMax(ndp[i + p][j][t], dp[i][j][t] + h); 
					if (j + p <= v2)
						updMax(ndp[i][j + p][t], dp[i][j][t] + h);
					if (s == 0)
						updMax(ndp[i][j][t], dp[i][j][t]);
				}
				updMax(ndp[i][j][1], dp[i][j][0] + h);
			}
		}
		FOR (i, 0, v1 + 1) FOR (j, 0, v2 + 1) FOR(k, 0, 2) dp[i][j][k] = ndp[i][j][k];
	}
	int ans = -1;
	FOR (i, 0, v1 + 1)
		FOR (j, 0, v2 + 1)
			FOR (k, 0, 2)
				updMax(ans, dp[i][j][k]);
	cout << ans << '\n' << '\n';
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	for (int tc = 1; ; tc++)
	{
		cin >> v1 >> v2 >> n;
		if (v1 == 0)
			break;
		cout << "Case " << tc << ": "; 
		solve();
	}
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 401ms
memory: 4004kb

input:

301 28 27
42 801 1
313 1 0
2 911 0
320 1 0
2 776 1
15 530 0
1 157 1
8 464 1
5 562 1
1 180 1
317 1 0
312 1 0
315 1 0
6 645 0
300 2 0
2 175 1
319 1 0
316 1 0
2 147 1
99 342 1
314 1 0
72 335 1
318 1 0
311 1 0
6 624 1
7 92 1
59 951 1
477 28 18
478 1 1
2 363 1
495 123 0
489 123 0
288 683 1
487 123 0
494 ...

output:

Case 1: 7694

Case 2: 4054

Case 3: -1

Case 4: -1

Case 5: 19645

Case 6: 14672

Case 7: -1

Case 8: 10284

Case 9: 18336

Case 10: -1

Case 11: 26657

Case 12: 39008

Case 13: 41077

Case 14: 46207

Case 15: 42054

Case 16: 31410

Case 17: 28908

Case 18: 24359

Case 19: 35273

Case 20: 34010


result:

ok 39 lines