P1450 [HAOI2008] Coin Shopping

Source: Internet
Author: User

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

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.