TLE求优化
查看原帖
TLE求优化
1414950
a_void楼主2024/11/26 23:05

TLE

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
const int M=6e3+5;
int T;
int dp[N][M];
int tot;
void dfdp(int u){
	int t,num;
	int ls,rs;
	cin>>t>>num;
	t*=2;
	if(num!=0){
		for(int i=1;i<=num and 5*i+t<=T;i++)
			for(int k=5*i;k<5*(i+1) and k+t<=T;k++)
				dp[u][k+t]=i;
		return;
	}
	ls=++tot;
	dfdp(ls);
	rs=++tot;
	dfdp(rs);
	for(int l=0;l<=T;l++)
		for(int r=0;l+r+t<=T;r++)
			dp[u][l+r+t]=max(dp[u][l+r+t],dp[ls][l]+dp[rs][r]);
	return;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>T;
	tot=1;
	dfdp(tot);
	cout<<dp[1][T-1];
	return 0;
}
2024/11/26 23:05
加载中...