背包问题,没啥好说的,记得用long long,否则会爆
代码:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; #define MAX_N 256
#define MAX_M 64 long long f[MAX_N];
int c[MAX_M];
int m, n; int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
cin >> n >> m;
for (int i = ; i < m; i++)
cin >> c[i]; memset(f, , sizeof(f));
f[] = ;
for (int i = m - ; i >= ; i--)
for (int j = ; j <= n; j++)
if (j >= c[i])
f[j] += f[j - c[i]]; cout << f[n] << endl;
return ;
}