3163: [Heoi2013]eden's new backpack problem

Source: Internet
Author: User

The main topic: There are now n items, the article I items have c[i], each purchase of the item I a need a[i] yuan, can get b[i] price.
There are m inquiries, each inquiry form such as: The x item is forbidden to buy, you have y yuan, you can get the maximum value is how much. Inquiries are independent of each other.

CDQ: Division of Treatment
Solve (L,r) indicates that the currently maintained DP array, the answer to the record is to remove the answer to the item outside [L,R]
Solve (L,MID), the DP array is transferred with an item in [Mid+1,r]. When l=r, all ban=l=r queries are together (check DP array for answers)

My Harvest: 233

```#include <bits/stdc++.h> using namespace std;

const int n=611111,v=2111;
int n,m;
int c[n],limit[n],w[n];

int dp[15][v],ans[n];
struct que{int pos,val;
Que (int a=0,int b=0) {pos=a;val=b;

}}q[n]; struct Edge{int Pos,money,nex;}

E[n];

void Dynamic_pro (int *f,int x) {for (int i=0;i<c[x];i++) {int l=1,r=1;q[1]=que (0,f[i]);
for (int j=1;j*c[x]<= (1000-i); j + +) {while (l<=r&&q[r].val<=f[j*c[x]+i]-j*w[x]) r--;
Q[++r]=que (J,f[j*c[x]+i]-j*w[x]);
while (L<=r&&q[l].pos<j-limit[x]) l++;
F[j*c[x]+i]=max (F[j*c[x]+i],q[l].val+j*w[x]); }}} void solve (int l,int r,int d) {if (l==r) {for (int I=head[l];~i;i=e[i].nex) ans[e[i].pos]=dp[d-1][e[i
].money];
return;
} int mid= (L+R) >>1;
for (int i=0;i<v;i++) dp[d][i]=dp[d-1][i]; for (iNT i=mid+1;i<=r;i++) Dynamic_pro (dp[d],i);
Solve (l,mid,d+1);
for (int i=0;i<v;i++) dp[d][i]=dp[d-1][i];
for (int i=l;i<=mid;i++) Dynamic_pro (dp[d],i);
Solve (mid+1,r,d+1);
} void Work () {scanf ("%d", &m);
for (int i=1;i<=m;i++) {int b,c;scanf ("%d%d", &b,&c);
} solve (1,n,1);
for (int i=1;i<=m;i++) printf ("%d\n", Ans[i]);
scanf ("%d", &n);
for (int i=1;i<=n;i++) scanf ("%d%d%d", &c[i],&w[i],&limit[i]);
} int main () {init ();
Work ();
return 0; }```
Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.