洛谷 P5020 货币系统 题解
每日一题 day7 打卡 Analysis 完全背包+筛法 只用完全背包会超时,所以要用筛法的思想来优化:筛去所有可以用已知货币系统中的面值表示出来的金额 80分 不用筛法 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define maxn 100+10 6 #define maxnum 25000+10 7 #define INF 2147483647/2-1 8 using namespace std; 9 inline int read() 10 { 11 int x=0; 12 bool f=1; 13 char c=getchar(); 14 for(; !isdigit(c); c=getchar()) if(c=='-') f=0; 15 for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+c-'0'; 16 if(f) return x; 17 return 0-x; 18 } 19 inline void write(int x) 20 { 21 if(x<0){putchar('-');x=-x;} 22 if(x>9)write(x/10); 23 putchar(x%10+'0'); 24 }