zoukankan      html  css  js  c++  java
  • luogu5020 [NOIp2018]货币系统 (完全背包)

    我那个新的货币系统,就是把原来的货币系统中能被其他数表示的数删掉

    那我就算有多少数能被别的数表示,那肯定是要被比它小的表示

    于是排个序做完全背包就好了

    但是我太zz不会完全背包,然后写了个bitset乱搞还开了250000,T到亲妈都不认识

    其实完全背包就是把背包的从后往前更新变成了从前往后更新

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<bitset>
     5 using namespace std;
     6 typedef long long ll;
     7 const int maxn=105,maxa=250;
     8 
     9 inline ll rd(){
    10     ll x=0;char c=getchar();int neg=1;
    11     while(c<'0'||c>'9'){
    12         if(c=='-') neg=-1;
    13         c=getchar();
    14     }
    15     while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    16     return x*neg;
    17 }
    18 
    19 int a[maxn],N;
    20 bool f[25005];
    21 
    22 int main(){
    23     // freopen("money.in","r",stdin);
    24     // freopen("money.out","w",stdout);
    25     int i,j,k;
    26     for(int T=rd();T;T--){
    27         N=rd();
    28         int ans=N;
    29         for(i=1;i<=N;i++) a[i]=rd();
    30         memset(f,0,sizeof(f));
    31         sort(a+1,a+N+1);
    32         int M=a[N];
    33         f[0]=1;
    34         for(i=1;i<=N;i++){
    35             if(f[a[i]]) ans--;
    36             else{
    37                 for(j=a[i];j<=M;j++){
    38                     f[j]|=f[j-a[i]];
    39                 }
    40             }
    41         }
    42         printf("%d
    ",ans);
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    python中的各种排序
    python 实现求和、计数、最大最小值、平均值、中位数、标准偏差、百分比。
    python中的lambda
    python中有趣的函数
    python中的小技巧
    python 删除list中重复元素
    django-pagination的使用
    django-south
    ios复制到剪贴板
    iOS系统验证关闭
  • 原文地址:https://www.cnblogs.com/Ressed/p/9981924.html
Copyright © 2011-2022 走看看