Bzoj 1042 Coin Shopping

Source: Internet
Author: User

First, regardless of the limit, then there is dp[i] represents the number of solutions I yuan.

Then consider the limitations, and find that they can be dismissed.

In fact, the whole problem is two of the principle of repulsion. Feel the good.

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMAXN 100500using namespacestd;Long Longf[maxn],c[5],d[5],n,s,ans;voidPRE_DP () {f[0]=1;  for(Long LongI=1; i<=maxn- -; i++)    {         for(Long Longj=1; j<=4; j + +)            if(I>=c[j]) f[i]+=f[i-C[j]];  for(Long Longj=1; j<=4; j + +)             for(Long Longk=j+1; k<=4; k++)                if(I>=c[j]+c[k]) f[i]-=f[i-c[j]-C[k]];  for(Long Longj=1; j<=4; j + +)             for(Long Longk=j+1; k<=4; k++)                 for(Long Longl=k+1; l<=4; l++)                    if(I>=c[j]+c[k]+c[l]) f[i]+=f[i-c[j]-c[k]-C[l]]; if(i>=c[1]+c[2]+c[3]+c[4]) f[i]-=f[i-c[1]-c[2]-c[3]-c[4]]; }}voidWork () {ans=0; ans+=F[s];  for(Long LongI=1; i<=4; i++)if(S>=d[i]*c[i]) ans-=f[s-d[i]*C[i]];  for(Long LongI=1; i<=4; i++)         for(Long Longj=i+1; j<=4; j + +)            if(S>=d[i]*c[i]+d[j]*c[j]) ans+=f[s-d[i]*c[i]-d[j]*C[j]];  for(Long LongI=1; i<=4; i++)         for(Long Longj=i+1; j<=4; j + +)             for(Long Longk=j+1; k<=4; k++)                if(S>=d[i]*c[i]+d[j]*c[j]+d[k]*c[k]) ans-=f[s-d[i]*c[i]-d[j]*c[j]-d[k]*C[k]]; if(s>=d[1]*c[1]+d[2]*c[2]+d[3]*c[3]+d[4]*c[4]) ans+=f[s-(d[1]*c[1]+d[2]*c[2]+d[3]*c[3]+d[4]*c[4])]; printf ("%lld\n", ans);}intMain () { for(Long LongI=1; i<=4; i++) scanf ("%lld",&C[i]); scanf ("%lld",&N);    PRE_DP ();  for(Long LongI=1; i<=n;i++)    {         for(Long Longj=1; j<=4; j + +) {scanf ("%lld", &d[j]);d [j]++;} scanf ("%lld",&s);    Work (); }    return 0;}

Bzoj 1042 Coin Shopping

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.