社区讨论
全WA爆零
P1270“访问”美术馆参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi6vmxba
- 此快照首次捕获于
- 2025/11/20 11:33 4 个月前
- 此快照最后确认于
- 2025/11/20 11:33 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int dp[50004][604],t,cnt=0,a[50004],cost[50004],lc[50004],rc[50004];
void dfs(int d,int k,int b){
a[++cnt]=b;cost[cnt]=k;
if(b>0) return;
int x,y;
cin>>x>>y;
lc[d]=cnt+1;
dfs(cnt+1,x,y);
cin>>x>>y;
rc[d]=cnt+1;
dfs(cnt+1,x,y);
}
void treedp(int root,int ti){
if(ti<=0) return;
if(dp[root][ti]) return;
if(lc[root]==0) {
if(ti>=5+2*cost[root]) dp[root][ti]=a[root];
return;
}int maxx=0;int tj=ti-2*cost[root];
for(int i=0;i<=tj;i++){
int j=tj-i;
treedp(lc[root],i);
treedp(rc[root],j);
maxx=max(maxx,dp[lc[root]][i]+dp[rc[root]][j]);
}
dp[root][ti]=maxx;
return;
}
int main(){
cin>>t;int x,y;t--;
cin>>x>>y;dfs(1,x,y);
// for(int i=1;i<=cnt;i++) cout<<cost[i]<<" "<<lc[i]<<" "<<rc[i]<<" "<<a[i]<<endl;
treedp(1,t);
cout<<dp[1][t];
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...