題意:問可以得到多少種可能湊成的價格
思路:完全背包的模板
#include#include #include #include using namespace std; const int MAXN = 110; int val[MAXN],num[MAXN]; int f[100005],n,v; int main(){ while (scanf("%d%d",&n,&v) != EOF && n+v){ for (int i = 1; i <= n; i++) scanf("%d",&val[i]); for (int i = 1; i <= n; i++) scanf("%d",&num[i]); memset(f,0,sizeof(f)); f[0] = 1; for (int i = 1; i <= n; i++){ int x = val[i],y = num[i]; int t = 1; while (y){ for (int j = v; j >= x*t; j--) if (f[j-x*t]) f[j] = 1; y -= t; t = min(y,2*t); } } int ans = 0; for (int i = 1; i <= v; i++) ans += f[i]; printf("%d\n",ans); } }