1708. [Usaco2007 Oct]Money奶牛的硬币
一眼完全背包统计方案数,有啥好说的...
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } const int N=10007,M=27; int n,m,a[M]; ll f[N]; int main() { n=read(),m=read(); f[0]=1; for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=n;i++) for(int j=a[i];j<=m;j++) f[j]+=f[j-a[i]]; printf("%lld\n",f[m]); return 0; }