Bzoj1531: [poi2005] bank notes

Source: Internet
Author: User
1531: [poi2005] Bank notestime limit: 5 sec memory limit: 64 MB
Submit: 229 solved: 119
[Submit] [Status] Descriptionbyteotian bit Bank (BBB) has an advanced currency system. This system has n kinds of coins with nominal values: B1, B2 ,..., bn. but there is a limit on the number of each coin, and now we want to raise the face value K to find the minimum number of coins to use. the first row of input contains N, 1 <=n <= 200. the next line contains N integers b1, b2 ,..., BN, 1 <= b1 <b2 <... <B n <= 20 000, N integers in the third row C1, C2 ,..., CN, 1 <= CI <= 20 000, indicating the number of each coin. the number K in the last row indicates the number of faces to be merged, 1 <= k <= 20 000. the first line of output indicates the number of coins to be paid at least. sample input sample output hint Source

Question:

It should be regarded as a bare multi-bag problem.

By the way, I reviewed the monotonous queue Optimization of multiple backpacks.

It seems very good: for the I-th item, we know the volume V, the value W, and the number K.

We can separate each part, assuming that the remainder is D.
After you see the group, number J can be transferred from J-K to any number in the J-1
Yes (because the adjacent volume is exactly different from V), which seems to be a bit similar to the maximum value of the interval.
However, because the volume is different, it is clear that the value of the volume is greater than or equal to the size of the small,
Direct comparison is meaningless, so we need to correct the value to the same volume. Ratio
For example, all data degrades to D, that is, F [J * V + D]-J * W is used to replace the original value into the queue.

 

Code:

 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 5000014 #define maxm 500+10015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 #define for0(i,n) for(int i=0;i<=(n);i++)19 #define for1(i,n) for(int i=1;i<=(n);i++)20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)22 #define mod 100000000723 using namespace std;24 inline int read()25 {26     int x=0,f=1;char ch=getchar();27     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}28     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}29     return x*f;30 }31 int n,m,a[maxn],b[maxn],f[maxn];32 struct rec{int x,y;}q[maxn];33 int main()34 {35     freopen("input.txt","r",stdin);36     freopen("output.txt","w",stdout);37     n=read();38     for1(i,n)a[i]=read();39     for1(i,n)b[i]=read();40     m=read();41     memset(f,60,sizeof(f));42     f[0]=0;43     for1(i,n)44     {45      for0(j,a[i]-1)46       {47           int l=1,r=0;48         for0(k,(m-j)/a[i])49          {50              int t=k*a[i]+j;51              while(l<=r&&q[r].y>f[t]-k)r--;52              q[++r].x=k;q[r].y=f[t]-k;53              while(l<=r&&q[l].x<k-b[i])l++;54              if(l<=r)f[t]=min(f[t],q[l].y+k);55          }56       }57     }58     printf("%d\n",f[m]);59     return 0;60 }
View code

 

Bzoj1531: [poi2005] bank notes

Contact Us

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.