zoukankan      html  css  js  c++  java
  • P5020 [NOIP2018 提高组] 货币系统

    如果某种面额的货币可以被同样存在于货币系统中的一些面额更小的货币表示出,那么它删去与否等价。

    当不能删时,从小到大考虑,因为不能出现面额更小的货币,所以该种面额的货币是必要的。

    所以从小到大跑完全背包,每次判断是否必要即可。

    尝试了一种二进制拆分(这里其实是倍增)加 bitset 优化完全背包的方法,这部分时间复杂度 (O(frac{nalog a}{w})),对比普通完全背包的 (O(na)) 优势很大。

    code:

    #include<bits/stdc++.h>
    using namespace std;
    #define For(i,x,y)for(i=x;i<=(y);i++)
    int a[105];
    bitset<25005>f;
    int read()
    {
    	int A;
    	bool K;
    	char C;
    	C=A=K=0;
    	while(C<'0'||C>'9')K|=C=='-',C=getchar();
    	while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
    	return(K?-A:A);
    }
    int main()
    {
    	int t,n,s,i,j;
    	t=read();
    	while(t--)
    	{
    		n=read();
    		s=0;
    		For(i,1,n)a[i]=read();
    		sort(a+1,a+n+1);
    		f=1;
    		For(i,1,n)
    		if(!f[a[i]])
    		{
    			j=a[i];
    			while(j<=a[n])f|=f<<j,j<<=1;
    			s++;
    		}
    		cout<<s<<endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    AC3 encoder flow
    AC3 IMDCT
    AC3 Rematrix
    AC3 channel coupling
    AC3 mantissa quantization and decoding
    AC3 bit allocation
    AC3 exponent coding
    C# 判断字符串为数字 int float double
    vs 修改默认的调试浏览器
    visio 如何扩大画布大小
  • 原文地址:https://www.cnblogs.com/May-2nd/p/14901536.html
Copyright © 2011-2022 走看看