結果

問題 No.417 チューリップバブル
ユーザー ttkkggwwttkkggww
提出日時 2020-04-01 15:56:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 846 ms / 2,000 ms
コード長 1,307 bytes
コンパイル時間 1,738 ms
コンパイル使用メモリ 173,268 KB
実行使用メモリ 318,832 KB
最終ジャッジ日時 2023-09-09 05:33:02
合計ジャッジ時間 15,191 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
15,620 KB
testcase_01 AC 28 ms
15,620 KB
testcase_02 AC 28 ms
15,776 KB
testcase_03 AC 29 ms
15,588 KB
testcase_04 AC 7 ms
7,424 KB
testcase_05 AC 7 ms
7,464 KB
testcase_06 AC 33 ms
17,648 KB
testcase_07 AC 33 ms
17,748 KB
testcase_08 AC 64 ms
29,956 KB
testcase_09 AC 64 ms
30,008 KB
testcase_10 AC 129 ms
54,512 KB
testcase_11 AC 130 ms
54,692 KB
testcase_12 AC 129 ms
54,732 KB
testcase_13 AC 203 ms
83,252 KB
testcase_14 AC 205 ms
83,188 KB
testcase_15 AC 207 ms
83,284 KB
testcase_16 AC 208 ms
83,348 KB
testcase_17 AC 420 ms
161,068 KB
testcase_18 AC 419 ms
161,012 KB
testcase_19 AC 419 ms
161,016 KB
testcase_20 AC 416 ms
161,192 KB
testcase_21 AC 415 ms
161,196 KB
testcase_22 AC 415 ms
161,084 KB
testcase_23 AC 418 ms
161,304 KB
testcase_24 AC 415 ms
161,068 KB
testcase_25 AC 415 ms
161,024 KB
testcase_26 AC 292 ms
113,968 KB
testcase_27 AC 291 ms
113,912 KB
testcase_28 AC 414 ms
161,196 KB
testcase_29 AC 414 ms
161,040 KB
testcase_30 AC 413 ms
161,068 KB
testcase_31 AC 413 ms
161,144 KB
testcase_32 AC 4 ms
7,420 KB
testcase_33 AC 16 ms
11,576 KB
testcase_34 AC 140 ms
83,176 KB
testcase_35 AC 846 ms
318,736 KB
testcase_36 AC 838 ms
318,824 KB
testcase_37 AC 838 ms
318,728 KB
testcase_38 AC 839 ms
318,792 KB
testcase_39 AC 842 ms
318,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dp[201][201][2001];
//dp[i][j][k]
//iを頂点とした、jをの子までを選んでkのタイムでの最大の税収
//iそれぞれでナップサックみたいな感じ
vector<vector<pair<int,int>>> M;
vector<int> tax;
void dfs(int now,int p = -1)
{
	//cout<<now<<endl;
	for(int i = 0;i<201;i++)
	{
		for(int j = 0;j <2001;j++)
		{
			dp[now][i][j] = tax[now];
		}
	}
	int I = 0;
	for(int i = 0;i<M[now].size();i++)
	{
		if(M[now][i].first!=p)
		{
			dfs(M[now][i].first,now);
			for(int j = 0;j<2001;j++)
			{
				if(j-M[now][i].second<0)
				{
					dp[now][I+1][j] = dp[now][I][j];
					continue;
				}
				for(int k = 0;j-M[now][i].second-k>=0;k++)
				{
					dp[now][I+1][j] = max(max(dp[now][I][j],
								dp[now][I+1][j]),
					dp[now][I][j-M[now][i].second-k]
					+dp[M[now][i].first][0][k]);
				}
			}
			I++;
		}
	}
	for(int i = 0;i<2001;i++)
	{
		dp[now][0][i] = dp[now][I][i];
	}
}


int main()
{
	int n;
	cin >> n;
	int m;
	cin >> m;
	tax = vector<int>(n);
	for(int i = 0;i<n;i++)
	{
		cin >> tax[i];
	}
	M = vector<vector<pair<int,int>>>(n);
	for(int i = 0;i<n-1;i++)
	{
		int x,y,z;
		cin >> x >> y >> z;
		M[x].emplace_back(y,z);
		M[y].emplace_back(x,z);
	}
	dfs(0);
	cout<<dp[0][0][m/2]<<endl;
	return 0;
}
0