1 solutions
-
0
C++ :
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int n,m,v,x,y,k,l,num; int a[301][3]; int f[301][601]; int t[301]; int m_max(int x,int y) { if(x>y) return x; else return y; } void init(int); void treedp(int); int main() { //freopen("steal.in","r",stdin); //freopen("steal111.out","w",stdout); cin>>v; num=1; init(1); treedp(1); cout<<f[1][v-1]<<endl; return 0; } void init(int now) { cin>>t[now]>>k; if(k==0) { num++; a[now][1]=num; init(num); num++; a[now][2]=num; init(num); } else { for(int i=1;i<=k;i++) { cin>>x>>y; for(int j=v;j>=t[now]+t[now]+y;j--) { f[now][j]=max(f[now][j],f[now][j-y]+x); // cout<<"f["<<now<<"]["<<j<<"]="<<f[now][j]<<' '; } //cout<<endl; } } } void treedp(int now) { if(a[now][1]+a[now][2]==0) return; treedp(a[now][1]); treedp(a[now][2]); for(int i=0;i<=v;i++) for(int j=i-t[now]-t[now];j>=0;j--) f[now][i]=max(f[now][i],f[a[now][1]][j]+f[a[now][2]][i-j-t[now]-t[now]]); }
- 1
Information
- ID
- 17802
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By