Test Instructions:Link
Method:Principle of tolerance and repulsion
parsing:Simple question, do not drop the pit are sorry my own this problem is very good to think of a tolerant principle, because there are only four kinds of coins, we are not convenient to calculate the number of solutions to meet the requirements of the problem, but from the reverse thinking, we need to do is to reduce the odd number of coins with excess, and then add an even number of coins Of course the state is 0000 when viewed as a benchmark). And then I have nothing to say, just have some details to note: 1. To use a long long2. Full backpack do not be silly to back every time, direct pretreatment is good, but why should I back ah! (8s difference)
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 100010Using namespace Std;typedef long long ll;intc[5],tot;intd[5],s; ll F[n];void Backpack (intW) {memset (F,0, sizeof (f)); f[0]=1; for(intI=1; i<=4; i++) { for(intj=c[i];j<=w;j++) {f[j]+=f[j-c[i]]; }}}ll Solve () {ll ans=0; for(intI=0;i< (1<<4); i++) {inttmp=s, flag=0; for(intj=1; j<=4; j + +) {if(i& (1<< (J-1))) tmp-= (d[j]+1)*c[j],flag^=1; }if(tmp<0)Continue; Backpack (TMP);if(flag) ans-=f[tmp];ElseANS+=F[TMP]; }returnAns;}intMain () {scanf ("%d %d%d%d%d", &c[1],&c[2],&c[3],&c[4],&tot); while(tot--) {scanf ("%d %d%d%d%d", &d[1],&d[2],&d[3],&d[4],&s); llPrint=solve ();if(Print<0)printf("0\n");Else printf("%lld\ n",Print); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Bzoj 1042 [HAOI2008] Coin shopping allowance principle