[AcWing 278] 数字组合
作者:互联网
点击查看代码
#include<iostream>
using namespace std;
const int N = 110, M = 10010;
int n, m;
int a[N];
int f[M];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++) cin >> a[i];
f[0] = 1;
for (int i = 1; i <= n; i ++)
for (int j = m; j >= a[i]; j --)
f[j] += f[j - a[i]];
cout << f[m] << endl;
return 0;
}
- 状态表示
\(f[i][j]\) 表示所有从前 \(i\) 个物品中选,且总体积是 \(j\) 的选法的个数 - 状态计算
\(f[i][j] = f[i - 1][j] + f[i - 1][j - a[i]]\)
标签:const,cout,组合,int,选法,110,278,AcWing 来源: https://www.cnblogs.com/wKingYu/p/16388152.html