社区讨论

0pts 求调

P1064[NOIP 2006 提高组] 金明的预算方案参与者 1已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@mhjt05jx
此快照首次捕获于
2025/11/04 08:01
4 个月前
此快照最后确认于
2025/11/04 08:01
4 个月前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;

struct mainthing
{
	int v1, p1;
} a[61];

struct second
{
	int v2, p2;
} b[61][3];

int pp[61];

int f[61][32001];

int pos2[61];

int main()
{
	int n, m;
	cin >> n >> m;
	int pos1 = 0, zz = 0, mmj = 0, mmi = 0;
	for(int i = 1; i <= m; i++)
	{
		int x, y, z;
		cin >> x >> y >> z;
		if(z == 0)
		{
			pos1++;
			a[pos1].v1 = x;
			a[pos1].p1 = y;
			pos2[i] = pos1;
		}
		else 
		{
			pp[pos2[z]]++;
			b[z][pp[pos2[z]]].v2 = x;
			b[z][pp[pos2[z]]].p2 = y;
		}
	}
	for(int j = 0; j <= n; j++)
	{
		for(int i = 1; i <= pos1; i++)
		{
			int maxn = max(f[i - 1][j], f[i - 1][j - a[i].v1] + a[i].v1 * a[i].p1);
			if(pp[i] == 2)
			{
				maxn = max(maxn, f[i][j - a[i].v1 - b[i][1].v2] + a[i].v1 * a[i].p1  + b[i][1].v2 * b[i][1].p2);
				maxn = max(maxn, f[i][j - a[i].v1 - b[i][1].v2 - b[i][2].v2] + a[i].v1 * a[i].p1  + b[i][1].v2 * b[i][1].p2 + b[i][2].v2 * b[i][2].p2);
				maxn = max(maxn, f[i][j - a[i].v1 - b[i][2].v2] + a[i].v1 * a[i].p1  + b[i][2].v2 * b[i][2].p2);
			}
			if(pp[i] == 1)
			{
				maxn = max(maxn, f[i][j - a[i].v1 - b[i][1].v2] + a[i].v1 * a[i].p1  + b[i][1].v2 * b[i][1].p2);
			}
			
			f[i][j] = maxn;
		}
	}
	cout << f[pos1][n];
	return 0;
}

回复

3 条回复,欢迎继续交流。

正在加载回复...