luogu P3423 [POI2005]BAN-Bank Notes

Byteotian Bit Bank (BBB) ​​has an advanced currency system that a total of n denominations of coins in denominations of b1, b2, ..., bn. However, each coin has a limit on the number ci, and now we want Couchu how many coins face value of k seek the least use.

n<=200,bi<=20000,ci<=20000

Also output program. . . .

 

At first glance this question multiple backpack, then hit 65 points, the open O2 70 points. .

We may change in thinking, why choose how many to enumerate each currency, Just take one look at the front as long as the state took a record number, there is no residual judgment enough.

Of course, the first dimension for circulation is no longer the enumeration money, but face value.

Monotonous queue you want to use the binary split and no one stopped you QAQ

Code

  

#include<iostream>
#include<cstdio>
#include<cstring>
#define R register
using namespace std;
int n,k,b[210],c[210],cnt[210][20010],f[20010],ans[210];
inline int read(){
    char c=getchar();int x=0,flag=1;
    while(c<'0' || c>'9'){if(c=='-') flag=-1;c=getchar();}
    while(c>='0' && c<='9') x=(x<<1)+(x<<3)+c-'0',c=getchar();
    return x*flag;
}
int main(){
    n=read();
    for(R int i=1;i<=n;i++) b[i]=read();
    for(R int i=1;i<=n;i++) c[i]=read();
    k=read();
    memset(f,0x3f,sizeof(f));f[0]=0;
    for(R int i=1;i<=k;i++){
        int val=0; 
        for(R int j=1;j<=n;j++){
            if(i>=b[j]){
                if(f[i]>f[i-b[j]]+1 && cnt[j][i-b[j]]<c[j]){
                    f[i]=f[i-b[j]]+1;val=j;
                }
            }
        }
        cnt[val][i]=cnt[val][i-b[val]]+1;
        for(R int j=1;j<=n;j++) if(j!=val) cnt[j][i]=cnt[j][i-b[val]];
    }
    printf("%d\n",f[k]);
    for(R int i=1;i<=n;i++) printf("%d ",cnt[i][k]);return 0;
}

 

Guess you like

Origin www.cnblogs.com/SyhAKIOI/p/11670768.html