Bzoj 1042 [HAOI2008] Coin shopping allowance principle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.