百练 2855

include

include

include

using namespace std;

int n, ans;
int a[30];
int way[40][30];

int main() {
cin >> n;
memset(way, 0, sizeof(way));

for (int i = 1; i <= n; i++) {
    cin >> a[i];
    way[0][i] = 1;
}
way[0][0] = 1;
for (int w = 1; w <= 40; w++) {
    for (int k = 1; k <= n; k++) {
        way[w][k] = way[w][k - 1];
        if (w - a[k] >= 0 )
            way[w][k] += way[w - a[k]][k - 1];
    }
}
cout << way[40][n];
return 0;

}

你可能感兴趣的:(百练 2855)