bzoj1042: [HAOI2008] Coin Shopping

Source: Internet
Author: User

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

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.