|洛谷|動態規劃|P1164 小A點菜
阿新 • • 發佈:2019-02-16
http://www.luogu.org/record/lists?pid=P1164
01揹包方案數
#include<cstdio> #include<algorithm> #include<cstring> #define ms(i,j) memset(i,j, sizeof i); using namespace std; int n,m; int a[105]; int f[10005]; int main() { scanf("%d%d", &n, &m); for (int i=1;i<=n;i++) scanf("%d", &a[i]); ms(f,0); f[0] = 1; for (int i=1;i<=n;i++) for (int j=m;j>=a[i];j--) { f[j] += f[j-a[i]]; } printf("%d\n", f[m]); return 0; }