Meaning of the questions:
To two liters of a person, there are n tasks x, t, y, r, L s1 of the first stage to experience, up to the second stage experience s2
If you do not ascended level, select the task and time-consuming ti xi will get experience, if one liters before, then get r y experience and time-consuming, at least ask how much time can go up levels. (If you crossed the first level of the same experience plus overflow)
answer:
- A very simple 01 backpack but when the game has been wa5
- All tasks in the x can be a sort of
- For example, there are three tasks values of x 90 40 40 s1 = 100 can overflow 30
- 404,090 can be sorted 70
- The two are completely different sort of does not always missed this situation
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=600+10; ll dp[510][510]; const ll inf=1e18; struct node { int x,y,t,r; bool operator < (const node &b) const { return x<b.x; } }s[N]; int main() { int n; int x,y,r,t,s1,s2; cin>>n>>s1>>s2; for(int i=0;i<=s1;i++) { for(int j=0;j<=s2;j++) dp[i][j]=inf; } dp[0][0]=0; for(int i=1;i<=n;i++) scanf("%d%d%d%d",&s[i].x,&s[i].t,&s[i].y,&s[i].r); sort(s+1,s+1+n); for(int i=1;i<=n;i++) { x=s[i].x,t=s[i].t,y=s[i].y,r=s[i].r; for(int j=s1;j>=0;j--) for(int k=s2;k>=0;k--) if(dp[j][k]!=inf) { if(j<s1) { if(j+x<=s1) dp[j+x][k]=min(dp[j+x][k],dp[j][k]+t); else dp[s1][min(k+(j+x)-s1,s2)]=min(dp[s1][min(s2,k+(j+x)-s1)],dp[j][k]+t); } if(k<s2) { dp[j][min(k+y,s2)]=min(dp[j][min(k+y,s2)],dp[j][k]+r); } } } if(dp[s1][s2]==1e18) printf("-1"); else printf("%lld",dp[s1][s2]); return 0; }