The principle of good God's repulsion
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> #define REP (i,s,t) for (int i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (x,c,sizeof (x)) #define LL Long Longint Read () { int x=0;char c=getchar (); while (!isdigit (c)) C=getchar (); while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} const INT NMAX=1E5+5;LL f[nmax];int C[5],d[5];int main () { rep (i,1,4) C[i]=read (); F[0]=1; Rep (i,1,4) Rep (j,c[i],100000) f[j]+=f[j-c[i]]; int N=read (); Rep (i,1,n) { rep (j,1,4) D[j]=read (); int M=read (), Cnt,tmp;ll ans=0; Rep (j,0,15) { cnt=0;tmp=m; for (int k=j,t=1;k;k>>=1,t++) if (k&1) tmp-=c[t]* (d[t]+1), cnt++; if (tmp<0) continue; if (cnt&1) ans-=f[tmp]; else ans+=f[tmp]; } printf ("%lld\n", ans); } return 0;}
1042: [HAOI2008] coin shopping time limit:10 Sec Memory limit:162 MB
submit:2054 solved:1206
[Submit] [Status] [Discuss] Description
Coin shopping A total of 4 kinds of coins. The denominations were c1,c2,c3,c4. Someone went to the store to buy something and went to tot. Each time with a di ci coin, buy s
I have something of value. How many methods of payment do you have each time?
Input
The first line C1,c2,c3,c4,tot below the tot line d1,d2,d3,d4,s, where di,s<=100000,tot<=1000
Output
Number of methods per time
Sample Input1 2 5) 10 2
3 2 3) 1 10
2 2 2Sample Output4
-HINT Source [Submit] [Status] [Discuss]
bzoj1042: [HAOI2008] Coin Shopping