P1450 [HAOI2008] Coin Shopping
Full Backpack + Capacity Scout
That's a second!
The number of scenarios statistics. If it is not possible to calculate directly, you can try to use the repulsion principle to cobble together.
You see, there are only 4 elements in this question that have an effect on the answer.
\ (2^n\) a second-party allowance can be done entirely
We can use all the number of schemes, minus the number of illegal schemes of one coin, plus the number of illegal schemes of two coins, and then engage in this.
You can do it.
#include <cstdio> #include <algorithm> #include <iostream> #include <cstring>const int maxn= 101000;long long F[maxn+1000];long long D[5],d[5];int main () {Long long tot=0; for (int i=0;i<=3;i++) scanf ("%lld", &d[i]); scanf ("%lld", &tot); F[0]=1; /*for (int i=1;i<maxn;i++) for (int j=1;j<=4;j++) {if (i-d[j]<0) continue; F[I]+=F[I-D[J]]; }*/for (int i=0;i<=3;i++) for (int j=d[i];j<=maxn;j++) f[j]+=f[j-d[i]];//does not consider limiting for (int i=1;i& lt;=tot;i++) {Long long c,s; int T; for (int j=0;j<=3;j++) scanf ("%lld", &d[j]); scanf ("%lld", &s); int ans=0; for (int j=0;j<16;j++) {c=s; t=0; for (int k=0;k<=3;k++) if (j& (1<<k)) {c-= (d[k]+1) *d[k];//calculation is incompatible The numerical t^=1 of the method; } if (c<0) continue; Ans=ans+ (T. -1:1) *f[c];//for the allowance} printf ("%lld\n", ans); }}
P1450 [HAOI2008] coin shopping